mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
[Events] Restrict bot to configured guild. (#26)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { Client, Guild } from 'discord.js';
|
import { Client, Guild } from 'discord.js';
|
||||||
|
import { config } from '../../config';
|
||||||
import { Database } from '../../shared/Database';
|
import { Database } from '../../shared/Database';
|
||||||
import { Event } from '../../types';
|
import { Event } from '../../types';
|
||||||
|
|
||||||
@@ -6,6 +7,11 @@ class GuildCreateEvent implements Event<Client, 'guildCreate'> {
|
|||||||
event = 'guildCreate' as const;
|
event = 'guildCreate' as const;
|
||||||
|
|
||||||
async execute(context: Client<boolean>, guild: Guild): Promise<void> {
|
async execute(context: Client<boolean>, guild: Guild): Promise<void> {
|
||||||
|
if (guild.id != config.DISCORD_GUILD_ID) {
|
||||||
|
await guild.leave();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await Database.getOrCreateSettings(guild.id);
|
await Database.getOrCreateSettings(guild.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
client.on('clientReady', async () => {
|
client.on('clientReady', async () => {
|
||||||
console.log(`Logged in as ${client.user!.tag}!`);
|
console.log(`Logged in as ${client.user!.tag}!`);
|
||||||
|
|
||||||
|
for (const guild of client.guilds.cache.values()) {
|
||||||
|
if (guild.id != config.DISCORD_GUILD_ID) await guild.leave();
|
||||||
|
}
|
||||||
|
|
||||||
await loadHandlersFrom('commands', commands);
|
await loadHandlersFrom('commands', commands);
|
||||||
await loadHandlersFrom('context-menus', contextMenus);
|
await loadHandlersFrom('context-menus', contextMenus);
|
||||||
await loadHandlersFrom('menus', menus);
|
await loadHandlersFrom('menus', menus);
|
||||||
|
|||||||
Reference in New Issue
Block a user