Files
discord.js/docs/examples/greeting.js
2017-04-30 04:30:44 +02:00

36 lines
1.2 KiB
JavaScript

/*
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 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 => {
// Send the message to the guilds default channel (usually #general), mentioning the member
member.guild.defaultChannel.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;
// Send the message, mentioning the member
channel.send(`Welcome to the server, ${member}`);
});
// Log our bot in
client.login(token);