diff options
| author | Mathias Magnusson <mathias@magnusson.space> | 2026-01-21 16:06:21 +0100 |
|---|---|---|
| committer | Mathias Magnusson <mathias@magnusson.space> | 2026-01-21 16:06:21 +0100 |
| commit | 0f28dfc85127badd5333bf99060a905835aac224 (patch) | |
| tree | 9c1c0744c30da7192b5959380290026258e5632d /index.ts | |
| parent | 1d6bd068ccec00486cc99e2b35a746d1afaf3764 (diff) | |
| download | challe-anka-0f28dfc85127badd5333bf99060a905835aac224.tar.gz | |
fix permissions stuff
Diffstat (limited to 'index.ts')
| -rw-r--r-- | index.ts | 32 |
1 files changed, 27 insertions, 5 deletions
@@ -1,8 +1,8 @@ import { Client, - CommandInteraction, Events, GatewayIntentBits, + PermissionFlagsBits, REST, Routes, } from "discord.js"; @@ -26,8 +26,30 @@ let client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits. let rest = new REST({ version: "10" }).setToken(token); -client.once(Events.ClientReady, (readyClient) => { - console.log(`Logged in as ${readyClient.user.tag}`); +client.once(Events.ClientReady, (c) => { + console.log(`Logged in as ${c.user.tag}`); +}); + +client.on(Events.GuildAvailable, guild => { + console.log(`Available in Guild: ${guild.name}`); + let role = guild.roles.botRoleFor(guild.client.user); + if (!role) { + console.error(`Bot has no role in ${guild.name}`); + return; + } + for (let permission of [ + PermissionFlagsBits.ViewChannel, + PermissionFlagsBits.ManageChannels, + PermissionFlagsBits.ManageRoles, + PermissionFlagsBits.SendMessages, + PermissionFlagsBits.SendMessagesInThreads, + PermissionFlagsBits.CreatePublicThreads, + PermissionFlagsBits.ManageThreads, + ]) { + if (!role.permissions.has(permission)) { + console.error(`Bot is missing permission ${permission} in ${guild.name}`); + } + } }); client.on(Events.InteractionCreate, async (interaction) => { @@ -50,8 +72,8 @@ client.on(Events.InteractionCreate, async (interaction) => { } } catch (error) { if (error === "done") return; - if (interaction instanceof CommandInteraction) { - console.error("Error while handling interaction", error); + console.error("Error while handling interaction", error); + if (interaction.isChatInputCommand() || interaction.isButton()) { if (interaction.deferred || interaction.replied) { await interaction.followUp({ content: "Something went wrong! :(", |
