Update examples

This commit is contained in:
Crawl
2017-04-24 08:34:00 +02:00
parent b15e012788
commit bbb5d4c7a1
4 changed files with 36 additions and 35 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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!');