mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
Update examples
This commit is contained in:
@@ -2,32 +2,33 @@
|
||||
A bot that welcomes new guild members when they join
|
||||
*/
|
||||
|
||||
// import the discord.js module
|
||||
// Import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
|
||||
// create an instance of a Discord Client
|
||||
// Create an instance of a Discord Client
|
||||
const client = new Discord.Client();
|
||||
|
||||
// the token of your bot - https://discordapp.com/developers/applications/me
|
||||
// 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.
|
||||
// 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
|
||||
// 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
|
||||
member.guild.defaultChannel.send(`Welcome to the server, ${member}!`);
|
||||
|
||||
// send the message, mentioning the member
|
||||
channel.send(`Welcome to the server, ${member}!`);
|
||||
// If you want to send the message to a designated channel on a server instead
|
||||
// you can do the following:
|
||||
const channel = member.guild.channels.find('name', 'member-log');
|
||||
// Do nothing if the channel wasn't found on this server
|
||||
if (!channel) return;
|
||||
channel.send(`Welcome to the server, ${member}`);
|
||||
});
|
||||
|
||||
// log our bot in
|
||||
// Log our bot in
|
||||
client.login(token);
|
||||
|
||||
Reference in New Issue
Block a user