Channel permission check

so i am trying to find if bot have permission to send message in channel or not, i using this code
// Check if the bot has permission to send messages in the music channel
if (!interaction.guild.members.me.permissionsIn(musicChannel).has(PermissionsBitField.Flags.SendMessages)) {
return interaction.reply("I don't have permissions to send messages in that channel.").catch(err => {
client.error(err);
});
}
// Check if the bot has permission to send messages in the music channel
if (!interaction.guild.members.me.permissionsIn(musicChannel).has(PermissionsBitField.Flags.SendMessages)) {
return interaction.reply("I don't have permissions to send messages in that channel.").catch(err => {
client.error(err);
});
}
also i have this options enable
props = {
partials: [
Partials.Channel, // for text channel
Partials.GuildMember, // for guild member
Partials.User, // for discord user
],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
],
}
props = {
partials: [
Partials.Channel, // for text channel
Partials.GuildMember, // for guild member
Partials.User, // for discord user
],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
],
}
15 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Mark
Mark7mo ago
And what's the problem?
Karlsefni
KarlsefniOP7mo ago
if statement is returning false but bot dont have any permission
Mark
Mark7mo ago
It should return false if it doesn't have the permission according to the code you showed I don't see the problem
Karlsefni
KarlsefniOP7mo ago
idk why it returning true either that why i created the post am i missing something?
Mark
Mark7mo ago
You can always log permissionsIn().serialize() and look at the permissions it lists
Karlsefni
KarlsefniOP7mo ago
{
CreateInstantInvite: true,
KickMembers: false,
BanMembers: false,
Administrator: false,
ManageChannels: false,
ManageGuild: false,
AddReactions: true,
ViewAuditLog: false,
PrioritySpeaker: false,
Stream: true,
ViewChannel: false,
SendMessages: true,
SendTTSMessages: false,
ManageMessages: false,
EmbedLinks: true,
AttachFiles: true,
ReadMessageHistory: true,
MentionEveryone: false,
UseExternalEmojis: true,
ViewGuildInsights: false,
Connect: false,
Speak: true,
MuteMembers: false,
DeafenMembers: false,
MoveMembers: false,
UseVAD: true,
ChangeNickname: true,
ManageNicknames: false,
ManageRoles: false,
ManageWebhooks: false,
ManageEmojisAndStickers: false,
ManageGuildExpressions: false,
UseApplicationCommands: true,
RequestToSpeak: true,
ManageEvents: false,
ManageThreads: false,
CreatePublicThreads: true,
CreatePrivateThreads: true,
UseExternalStickers: true,
SendMessagesInThreads: true,
UseEmbeddedActivities: true,
ModerateMembers: false,
ViewCreatorMonetizationAnalytics: false,
UseSoundboard: true,
CreateGuildExpressions: false,
CreateEvents: false,
UseExternalSounds: true,
SendVoiceMessages: true,
SendPolls: true
}
{
CreateInstantInvite: true,
KickMembers: false,
BanMembers: false,
Administrator: false,
ManageChannels: false,
ManageGuild: false,
AddReactions: true,
ViewAuditLog: false,
PrioritySpeaker: false,
Stream: true,
ViewChannel: false,
SendMessages: true,
SendTTSMessages: false,
ManageMessages: false,
EmbedLinks: true,
AttachFiles: true,
ReadMessageHistory: true,
MentionEveryone: false,
UseExternalEmojis: true,
ViewGuildInsights: false,
Connect: false,
Speak: true,
MuteMembers: false,
DeafenMembers: false,
MoveMembers: false,
UseVAD: true,
ChangeNickname: true,
ManageNicknames: false,
ManageRoles: false,
ManageWebhooks: false,
ManageEmojisAndStickers: false,
ManageGuildExpressions: false,
UseApplicationCommands: true,
RequestToSpeak: true,
ManageEvents: false,
ManageThreads: false,
CreatePublicThreads: true,
CreatePrivateThreads: true,
UseExternalStickers: true,
SendMessagesInThreads: true,
UseEmbeddedActivities: true,
ModerateMembers: false,
ViewCreatorMonetizationAnalytics: false,
UseSoundboard: true,
CreateGuildExpressions: false,
CreateEvents: false,
UseExternalSounds: true,
SendVoiceMessages: true,
SendPolls: true
}
Mark
Mark7mo ago
So it has the permission, but it is still returning the message saying it doesn't have it?
Karlsefni
KarlsefniOP7mo ago
dham when i check the json it said ViewChannel false no wonder it throwing error hahahaha
Mark
Mark7mo ago
There's that too, good catch, but I didn't think it'd cause that behavior
Karlsefni
KarlsefniOP7mo ago
well bot was crashing and throwing error rawError: { message: 'Missing Access', code: 50001 }, code: 50001, status: 403, method: 'POST',
Mark
Mark7mo ago
That is usually helpful to include when asking for help Because that would have pointed me in a different direction from the start
Karlsefni
KarlsefniOP7mo ago
sorry my bad thanx for the help
Mark
Mark7mo ago
Now you know for next time 🙃 Hope your project turns out well!
Karlsefni
KarlsefniOP7mo ago
thanx
Want results from more Discord servers?
Add your server