discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Sending embed with interaction.reply works but not with channel.send (permissions error) #7544

Closed ghost closed 2 years ago

ghost commented 2 years ago

Which package is this bug report for?

discord.js

Issue description

https://github.com/kennedybaird/discord-embed-error

Clone repository, npm install, create bot and add to testing server.

Use command /list-item issue: 2 ephemeral message will populate with embed

Use command /list-item issue: 1 tries to use channel.send to send an embed, but gives permissions error.

Error does not appear when setting bot permissions to administrator.

Permissions as so:

image

Code sample

No response

Package version

v13

Node.js version

16.13.2

Operating system

Linux

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMessages

I have tested this issue on a development release

No response

Jiralite commented 2 years ago

This isn't to do with discord.js, it's just as you're told: you don't have permissions. Additionally, the screenshot you provided doesn't have embed links enabled and people may take permissions away from your bot.

ghost commented 2 years ago

Thanks for the reply.

I am starting to wonder if it is an issue with discordjs as I am able to edit the reply with an embed, without those permissions.

Even with those permissions I cannot send the embed successfully.

Why can I edit the reply with an embed, but not send a new message to the channel with the embed?

monbrey commented 2 years ago

Permissions errors come from the Discord API, not discord.js. The library does not perform internal permissions checks.

ghost commented 2 years ago

Right, but that's still not explaining why it works when it's via interaction.reply and not working when it's from channel.send?

monbrey commented 2 years ago

Interaction replies use Webhooks to respond - their permissions are inherently tied to the everyone role, not your bot user.

ghost commented 2 years ago

Ah, that makes sense.

I have tried sitting there putting on all types of permissions for the deployment, and I can't seem to get it work.

It doesn't work with embed links turned on either as the user above suggested. Do you have any immediate thoughts?

I really appreciate the help - i've been stuck on this for ages

ghost commented 2 years ago

For example - putting every permission except for Administrator it still doesn't work:

image

Is it something I'm missing with Intents?


const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});```
SpaceEEC commented 2 years ago

Changing the values for the invite link won't change any already set permissions. You need to go into the relevant guild and grant the bot the permission(s) there.

ghost commented 2 years ago

Changing the values for the invite link won't change any already set permissions. You need to go into the relevant guild and grant the bot the permission(s) there.

Changing them and re-adding to the server does update the role assigned to the bot.

SpaceEEC commented 2 years ago

If the bot is having those permission on its integration role and you are getting that error when sending a message, then there is an overwrite denying the permission(s) in place.

ghost commented 2 years ago

Thanks - where can I troubleshoot what may be overwriting?

ghost commented 2 years ago

@SpaceEEC Ok, that was perfect, I found that @everyone had embed-links turned off for the channel.

Is there a way to have my bot not be defined / affected by over-writes like that?

SpaceEEC commented 2 years ago

Only by granting it the administrator permission. (You could also create an overwrite granting for the bot / integration role, allowing that bit, behaves slightly different, but would also work here)