mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Welcome example (#1194)
* Add user greeting example * Add welcome.js to index.yml * Reword greeting message * Update welcome.js * Rename welcome.js to greeting.js * Update index.yml
This commit is contained in:
committed by
Schuyler Cebulskie
parent
05bba9b74a
commit
12136f8c54
33
docs/examples/greeting.js
Normal file
33
docs/examples/greeting.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
A bot that welcomes new guild members when they join
|
||||
*/
|
||||
|
||||
// import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
|
||||
// create an instance of a Discord Client
|
||||
const client = new Discord.Client();
|
||||
|
||||
// the token of your bot - https://discordapp.com/developers/applications/me
|
||||
const token = 'your bot token here';
|
||||
|
||||
// the ID of the channel in which the bot will greet new users
|
||||
const channelID = 'your channel ID here';
|
||||
|
||||
// the ready event is vital, it means that your bot will only start reacting to information
|
||||
// from Discord _after_ ready is emitted.
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
// create an event listener for new guild members
|
||||
client.on('guildMemberAdd', member => {
|
||||
// get the channel by its ID
|
||||
const channel = client.channels.get(channelID);
|
||||
|
||||
// send the message, mentioning the member
|
||||
channel.sendMessage(`Welcome to the server, ${member}!`);
|
||||
});
|
||||
|
||||
// log our bot in
|
||||
client.login(token);
|
||||
@@ -16,5 +16,7 @@
|
||||
path: ping.js
|
||||
- name: Avatars
|
||||
path: avatars.js
|
||||
- name: Server greeting
|
||||
path: greeting.js
|
||||
- name: Webhook
|
||||
path: webhook.js
|
||||
|
||||
Reference in New Issue
Block a user