mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
* Bring some docs up to date, as well as add a new example * Missed an exclamation mark * Do requested changes * Do suggestions * Same suggestions for the other examples * Show people that they can also use reply with embeds * Typos in embed.js example * Remove object example from embeds, too complex Suggested by Yukine * Some changes, some requested changes * Add moderation examples! * Add attachment examples * Missing dot * Fix spacing * Requested Changes * Quote consistency * Tfw you break the syntax
31 lines
941 B
JavaScript
31 lines
941 B
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 ready event is vital, it means that only _after_ this will your bot start reacting to information
|
|
* received from Discord
|
|
*/
|
|
client.on('ready', () => {
|
|
console.log('I am ready!');
|
|
});
|
|
|
|
// Create an event listener for new guild members
|
|
client.on('guildMemberAdd', member => {
|
|
// Send the message to a designated channel on a server:
|
|
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 using the token from https://discordapp.com/developers/applications/me
|
|
client.login('your token here');
|