From 0f28dfc85127badd5333bf99060a905835aac224 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Wed, 21 Jan 2026 16:06:21 +0100 Subject: fix permissions stuff --- index.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'index.ts') diff --git a/index.ts b/index.ts index 9bf969d..fc65e3f 100644 --- a/index.ts +++ b/index.ts @@ -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! :(", -- cgit v1.2.3