-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbot.ts
53 lines (42 loc) · 1.44 KB
/
bot.ts
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
import { Client, Events, GatewayIntentBits, Snowflake } from 'discord.js';
import { readFileSync } from 'fs';
import config = require('./config');
const client = new Client({
intents: [
// TODO: adding all intents for now
// remove unnecessary ones
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
const modules = ['verification'];
client.once(Events.ClientReady, c => {
for (const module of modules) {
require('./' + module).setup(client, config);
}
// create slash command
const guild = client.guilds.cache.get(config.guild_2027);
let commands;
if (guild) {
commands = guild.commands;
} else {
commands = client.application?.commands;
}
commands?.create({
name: 'verify',
description: 'sends verification DM'
})
console.log(`Ready! Logged in as ${c.user.tag}`);
});
/// DM after successful verification
client.on(Events.GuildMemberUpdate, (oldMember, newMember) => {
const guild = client.guilds.cache.get(config.guild_2027);
const wasGivenRole = (role: Snowflake) => !oldMember.roles.cache.get(role) && newMember.roles.cache.get(role);
if (newMember.guild == guild && wasGivenRole(config.admitted_role_2027)) {
newMember.send(config.post_verification_dm);
}
});
const token = readFileSync('token.txt', 'utf-8');
client.login(token);