From 671be7797d005d99466644c606c3933f70df17bb Mon Sep 17 00:00:00 2001 From: moon Date: Mon, 4 Nov 2024 21:54:39 -0800 Subject: [PATCH] fix discord voice and dms --- core/src/clients/discord/messages.ts | 20 ++++++++++---------- core/src/clients/discord/voice.ts | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/clients/discord/messages.ts b/core/src/clients/discord/messages.ts index a387ae0f971..895b53eb860 100644 --- a/core/src/clients/discord/messages.ts +++ b/core/src/clients/discord/messages.ts @@ -112,7 +112,14 @@ function splitMessage(content: string): string[] { function canSendMessage(channel) { - // Get the bot member in the guild + console.log("canSendMessage", channel); + // if it is a DM channel, we can always send messages + if (channel.type === ChannelType.DM) { + return { + canSend: true, + reason: null + }; + } const botMember = channel.guild?.members.cache.get(channel.client.user.id); if (!botMember) { @@ -147,18 +154,11 @@ function canSendMessage(channel) { // Check each required permission const missingPermissions = requiredPermissions.filter(perm => !permissions.has(perm)); - // Convert BigInts to strings to avoid serialization issues - const missingPermNames = missingPermissions.map(perm => { - // Find the flag name by its value - return Object.entries(PermissionsBitField.Flags) - .find(([_, val]) => val === perm)?.[0] || String(perm); - }); - return { canSend: missingPermissions.length === 0, - missingPermissions: missingPermNames, // Now using string names instead of BigInts + missingPermissions: missingPermissions, reason: missingPermissions.length > 0 - ? `Missing permissions: ${missingPermNames.join(', ')}` + ? `Missing permissions: ${missingPermissions.map(p => String(p)).join(', ')}` : null }; } diff --git a/core/src/clients/discord/voice.ts b/core/src/clients/discord/voice.ts index c0f663d1546..ea331eaf912 100644 --- a/core/src/clients/discord/voice.ts +++ b/core/src/clients/discord/voice.ts @@ -680,4 +680,4 @@ export class VoiceManager extends EventEmitter { await interaction.reply("Failed to leave the voice channel."); } } -} +} \ No newline at end of file