-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservers.ts
More file actions
31 lines (25 loc) · 1.03 KB
/
servers.ts
File metadata and controls
31 lines (25 loc) · 1.03 KB
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
import {Server} from "./models/server";
import Discord from "discord.js";
import {ChannelType} from 'discord-api-types/v10';
export function createServer(guild: Discord.Guild,) {
const server = new Server({id: guild.id})
server.save().then()
return server
}
export async function init(client: Discord.Client) {
for (const g of await client.guilds.fetch()) {
const guild = await client.guilds.fetch(g[0])
let server = await Server.findOne({id: guild.id}).exec() || await createServer(guild);
// Cache reaction messages
for (let reactionRole of server.reactionRoles) {
const channel = await client.channels.fetch(reactionRole.channelId)
if (!channel || channel.type != ChannelType.GuildText) {
break;
}
const msg = await channel.messages.fetch(reactionRole.messageId)
reactionRole.messageId = msg.id
const role = await guild.roles.fetch(reactionRole.roleId)
reactionRole.roleId = role!.id
}
}
}