diff --git a/docs/examples/avatars.js b/docs/examples/avatars.js index cb496c5ae..b6779d043 100644 --- a/docs/examples/avatars.js +++ b/docs/examples/avatars.js @@ -2,29 +2,29 @@ Send a user a link to their avatar */ -// 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 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 messages +// Create an event listener for messages client.on('message', message => { - // if the message is "what is my avatar", + // If the message is "what is my avatar" if (message.content === 'what is my avatar') { - // send the user's avatar URL + // Send the user's avatar URL message.reply(message.author.avatarURL); } }); -// log our bot in +// Log our bot in client.login(token); diff --git a/docs/examples/greeting.js b/docs/examples/greeting.js index d2c1e1e58..c7d360c6b 100644 --- a/docs/examples/greeting.js +++ b/docs/examples/greeting.js @@ -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); diff --git a/docs/examples/ping.js b/docs/examples/ping.js index cf6d3c5f8..7a0d5870a 100644 --- a/docs/examples/ping.js +++ b/docs/examples/ping.js @@ -2,29 +2,29 @@ A ping pong bot, whenever you send "ping", it replies "pong". */ -// 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 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 messages +// Create an event listener for messages client.on('message', message => { - // if the message is "ping", + // If the message is "ping" if (message.content === 'ping') { - // send "pong" to the same channel. + // Send "pong" to the same channel message.channel.send('pong'); } }); -// log our bot in +// Log our bot in client.login(token); diff --git a/docs/examples/webhook.js b/docs/examples/webhook.js index 615fecdc0..fd8a567d1 100644 --- a/docs/examples/webhook.js +++ b/docs/examples/webhook.js @@ -2,11 +2,11 @@ Send a message using a webhook */ -// import the discord.js module +// Import the discord.js module const Discord = require('discord.js'); -// create a new webhook +// Create a new webhook const hook = new Discord.WebhookClient('webhook id', 'webhook token'); -// send a message using the webhook +// Send a message using the webhook hook.send('I am now alive!');