Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Discord Voice and DMs #203

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions core/src/clients/discord/messages.ts
Original file line number Diff line number Diff line change
@@ -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
};
}
2 changes: 1 addition & 1 deletion core/src/clients/discord/voice.ts
Original file line number Diff line number Diff line change
@@ -680,4 +680,4 @@ export class VoiceManager extends EventEmitter {
await interaction.reply("Failed to leave the voice channel.");
}
}
}
}