summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Magnusson <mathias@magnusson.space>2026-01-21 16:06:21 +0100
committerMathias Magnusson <mathias@magnusson.space>2026-01-21 16:06:21 +0100
commit0f28dfc85127badd5333bf99060a905835aac224 (patch)
tree9c1c0744c30da7192b5959380290026258e5632d
parent1d6bd068ccec00486cc99e2b35a746d1afaf3764 (diff)
downloadchalle-anka-0f28dfc85127badd5333bf99060a905835aac224.tar.gz
fix permissions stuff
-rw-r--r--commands.ts10
-rw-r--r--index.ts32
2 files changed, 36 insertions, 6 deletions
diff --git a/commands.ts b/commands.ts
index 7005165..3a4458f 100644
--- a/commands.ts
+++ b/commands.ts
@@ -113,6 +113,10 @@ async function newCtf(interaction: ChatInputCommandInteraction) {
let tags = interaction.options.getString("tags");
await interaction.deferReply({ flags: "Ephemeral" });
+ let botRole = interaction.guild.roles.botRoleFor(interaction.client.user);
+ if (!botRole)
+ throw new Error("Why does this bot not have a role???");
+
let forum = await interaction.guild.channels.create({
name,
type: ChannelType.GuildForum,
@@ -120,7 +124,11 @@ async function newCtf(interaction: ChatInputCommandInteraction) {
{
id: interaction.guild.roles.everyone,
deny: [PermissionFlagsBits.ViewChannel],
- }
+ },
+ {
+ id: botRole.id,
+ allow: [PermissionFlagsBits.ViewChannel],
+ },
],
});
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! :(",