Skip to content

Instantly share code, notes, and snippets.

@mderijcke
Last active August 17, 2018 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mderijcke/a261a151c9ebc9a5a4198f5b35be8a9c to your computer and use it in GitHub Desktop.
Save mderijcke/a261a151c9ebc9a5a4198f5b35be8a9c to your computer and use it in GitHub Desktop.
Discord newbies annoying notify bot
// Code released under Unlicense (https://unlicense.org/)
const Promise = require('bluebird');
const Discord = require('discord.js');
const fs = Promise.promisifyAll(require('fs'));
let client = new Discord.Client();
client.on('ready', async () => {
return Promise.try(async () => {
let guild = client.guilds.get('452308608990838814');
if (guild == null) {
throw new Error('Could not find guild');
}
await guild.fetchMembers();
let newbiesRole = guild.roles.get('477152733921542155');
if (newbiesRole == null) {
throw new Error('Could not find role');
}
await guild.fetchMembers();
if (newbiesRole.members.size == 0) {
throw new Error('No newbies to message!');
}
let welcomeChannel = guild.channels.get('473856722717376527');
if (welcomeChannel == null) {
throw new Error('Could not find #welcome-area');
}
let oldMessageId = await fs.readFileAsync('lastMessageId', 'utf8');
if (oldMessageId != null && oldMessageId.trim().length > 0) {
let oldMessage = await welcomeChannel.fetchMessage(oldMessageId.trim());
if (oldMessage != null) {
await oldMessage.delete();
}
}
await newbiesRole.setMentionable(true);
await Promise.delay(1000);
let message = await welcomeChannel.send('Hi ' + newbiesRole + ', than you all for joining! We would like to ask you to please introduce yourself in this channel. If you do so we can give you the role that suits you best. If you want to you can mention your portfolio / business website. We\'re excited to meet you!');
await fs.writeFileAsync('lastMessageId', message.id);
await Promise.delay(5000);
await newbiesRole.setMentionable(false);
}).finally(() => {
process.exit();
});
});
if (process.env.TOKEN == null || process.env.TOKEN.trim().length == 0) {
throw new Error('No Discord token provided');
}
client.login(process.env.TOKEN);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment