|
| 1 | +import Discord, { Interaction } from 'discord.js'; |
| 2 | +import { getVoiceConnection } from '@discordjs/voice'; |
| 3 | +import { deploy } from './deploy'; |
| 4 | +import { interactionHandlers } from './interactions'; |
| 5 | + |
| 6 | +// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports |
| 7 | +const { token } = require('../auth.json'); |
| 8 | + |
| 9 | +const client = new Discord.Client({ intents: ['GUILD_VOICE_STATES', 'GUILD_MESSAGES', 'GUILDS'] }); |
| 10 | + |
| 11 | +client.on('ready', () => console.log('Ready!')); |
| 12 | + |
| 13 | +client.on('messageCreate', async (message) => { |
| 14 | + if (!message.guild) return; |
| 15 | + if (!client.application?.owner) await client.application?.fetch(); |
| 16 | + |
| 17 | + if (message.content.toLowerCase() === '!deploy' && message.author.id === client.application?.owner?.id) { |
| 18 | + await deploy(message.guild); |
| 19 | + await message.reply('Deployed!'); |
| 20 | + } |
| 21 | +}); |
| 22 | + |
| 23 | +/** |
| 24 | + * The IDs of the users that can be recorded by the bot. |
| 25 | + */ |
| 26 | +const recordable = new Set<string>(); |
| 27 | + |
| 28 | +client.on('interactionCreate', async (interaction: Interaction) => { |
| 29 | + if (!interaction.isCommand() || !interaction.guildId) return; |
| 30 | + |
| 31 | + const handler = interactionHandlers.get(interaction.commandName); |
| 32 | + |
| 33 | + try { |
| 34 | + if (handler) { |
| 35 | + await handler(interaction, recordable, client, getVoiceConnection(interaction.guildId)); |
| 36 | + } else { |
| 37 | + await interaction.reply('Unknown command'); |
| 38 | + } |
| 39 | + } catch (error) { |
| 40 | + console.warn(error); |
| 41 | + } |
| 42 | +}); |
| 43 | + |
| 44 | +client.on('error', console.warn); |
| 45 | + |
| 46 | +void client.login(token); |
0 commit comments