Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
premium-bot/src/bot_step1.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (32 sloc)
1.09 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const eris = require('eris'); | |
| const { BOT_TOKEN } = require('../config.json'); | |
| // Create a Client instance with our bot token. | |
| const bot = new eris.Client(BOT_TOKEN); | |
| // When the bot is connected and ready, log to console. | |
| bot.on('ready', () => { | |
| console.log('Connected and ready.'); | |
| }); | |
| // Every time a message is sent anywhere the bot is present, | |
| // this event will fire and we will check if the bot was mentioned. | |
| // If it was, the bot will attempt to respond with "Present". | |
| bot.on('messageCreate', async (msg) => { | |
| const botWasMentioned = msg.mentions.find( | |
| mentionedUser => mentionedUser.id === bot.user.id, | |
| ); | |
| if (botWasMentioned) { | |
| try { | |
| await msg.channel.createMessage('Present'); | |
| } catch (err) { | |
| // There are various reasons why sending a message may fail. | |
| // The API might time out or choke and return a 5xx status, | |
| // or the bot may not have permission to send the | |
| // message (403 status). | |
| console.warn('Failed to respond to mention.'); | |
| console.warn(err); | |
| } | |
| } | |
| }); | |
| bot.on('error', err => { | |
| console.warn(err); | |
| }); | |
| bot.connect(); |