-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
71 lines (61 loc) · 2.85 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { default as config } from './config.js';
import * as commands from './commands/index.js';
import { handleApplication } from './lib/index.js'
import { Client, Intents } from 'discord.js'
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
});
// Register an event so that when the bot is ready, it will log a messsage to the terminal
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
})
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.channel.id !== config.applicationChannelId) {
console.log(reaction.message.channel.name);
console.log('ignoring message');
return;
}
console.log("Checking reactions for message");
try {
await handleApplication(client, reaction);
}
catch (err) {
console.log(err);
}
});
client.on('guildMemberUpdate', async(oldMember, newMember) => {
// check if the member was updated with the "member" role
if ((!oldMember.roles.cache.some(role => role.name === "Member")) && (
newMember.roles.cache.some(role => role.name === "Member"))) {
const channel = client.channels.cache.find(channel => channel.id === config.welcomeChannelId);
channel.send(`Applicant ${newMember} has been promoted to Blank member! Welcome! Feel free to look around, ask questions in #◽〡no-silly-questions and browse the resources in #◽〡links!`);
}
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'regenerate-voucher') {
await commands['regenerateVoucher'](interaction)
} else if (interaction.commandName === 'regenerate-all-vouchers') {
await commands['regenerateAllVouchers'](interaction)
} else if (interaction.commandName === 'nominate-voucher') {
await commands['nominateVoucher'](interaction)
} else if (interaction.commandName === 'approve-voucher') {
await commands['approveVoucher'](interaction)
} else if (interaction.commandName === 'list-vouchers') {
await commands['listVouchers'](interaction)
} else if (interaction.commandName === 'claim-voucher') {
await commands['claimVoucher'](interaction)
} else if (interaction.commandName === 'delete-voucher') {
await commands['deleteVoucher'](interaction)
} else if (interaction.commandName === 'redeem-voucher') {
await commands['redeemVoucher'](interaction)
} else if (commands[interaction.commandName]) {
await commands[interaction.commandName](interaction)
} else {
await commands['notfound'](interaction)
}
});
// client.login logs the bot in and sets it up for use. You'll enter your token here.
client.login(config.discordToken);