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

Using channel.send on a channel where the bot has not the permission to post makes the whole program crash #10319

Closed
gustaveWPM opened this issue Jun 3, 2024 · 3 comments
Labels

Comments

@gustaveWPM
Copy link

gustaveWPM commented Jun 3, 2024

Which package is this bug report for?

discord.js

Issue description

Invite a bot on a server and hide a text channel to it.
You should try to make the bot post on this channel. With the current behavior, it should crash, even if the call is protected by a try/catch block.

Code sample

Just write in a callback:

try {
  const channel = client.channels.cache.get(CHANNEL_ID);

  if (channel === undefined) return;
  if (channel.type === ChannelType.GuildText) channel.send('hello world');
} catch {}

Versions

"discord.js": "14.15.3",
"typescript": "5.4.5"
Node v20.13.1
Bun v1.1.12

Issue priority

Low (slightly annoying)

Which partials do you have configured?

User, Channel, GuildMember, Message, Reaction, GuildScheduledEvent, ThreadMember

Which gateway intents are you subscribing to?

3276799 (sorry, haven't more than this)

I have tested this issue on a development release

No response

@Renegade334
Copy link
Contributor

Renegade334 commented Jun 3, 2024

send is an async method, and you're not handling promise rejection. You need either to use the .catch() method on the returned Promise, or use an await expression.

@gustaveWPM
Copy link
Author

send is an async method, and you're not handling promise rejection. You need either to use the .catch() method on the returned Promise, or use an await expression.

Oh, thank you!
It will probably solve my issue.
I'll give it a look today. Sorry, some cognitive overload... lulz.

@almostSouji almostSouji closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2024
@gustaveWPM
Copy link
Author

Indeed, it was my fault. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants