From 12136f8c54d56e5c82ee6f618f4e071d7824e378 Mon Sep 17 00:00:00 2001 From: Jamelele Date: Sat, 18 Feb 2017 18:59:25 +0000 Subject: [PATCH] Welcome example (#1194) * Add user greeting example * Add welcome.js to index.yml * Reword greeting message * Update welcome.js * Rename welcome.js to greeting.js * Update index.yml --- docs/examples/greeting.js | 33 +++++++++++++++++++++++++++++++++ docs/index.yml | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 docs/examples/greeting.js diff --git a/docs/examples/greeting.js b/docs/examples/greeting.js new file mode 100644 index 000000000..15ce32711 --- /dev/null +++ b/docs/examples/greeting.js @@ -0,0 +1,33 @@ +/* + 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 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. +client.on('ready', () => { + console.log('I am ready!'); +}); + +// 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 + channel.sendMessage(`Welcome to the server, ${member}!`); +}); + +// log our bot in +client.login(token); diff --git a/docs/index.yml b/docs/index.yml index 94444f298..d35365af9 100644 --- a/docs/index.yml +++ b/docs/index.yml @@ -16,5 +16,7 @@ path: ping.js - name: Avatars path: avatars.js + - name: Server greeting + path: greeting.js - name: Webhook path: webhook.js