Runtime error when trying to send a message via Discord bot in my API

I’m working on an API that uses a Discord bot. I’m having trouble sending messages to a channel. It keeps giving me a runtime error. I tried using Discord webhooks instead. That worked for sending messages but I can’t add reactions to them. The webhook doesn’t return any data so I can’t get the message ID to add reactions.

Here’s what I’ve tried:

  • Using discord.py to send messages (got runtime error)
  • Using Discord webhooks (can’t add reactions)
  • Trying to use Discord API directly (couldn’t figure it out)

My code is trying to create a clan system. It checks if the user can make a clan then sends a message to a staff channel for approval. The error happens when trying to send that message.

Does anyone know how to fix this? Or maybe a different way to send messages and add reactions that won’t cause errors? Thanks for any help!

hey mate, i’ve had similar issues. have u tried using discord.ext.commands instead of plain discord.py? it’s way easier to work with imo. for the webhook thing, u could try sending the msg first then grabbing the id from the channel history. might be a bit slow tho. good luck!

I’ve encountered similar challenges with Discord bots. Have you considered using a library like discord.js instead? It offers more robust error handling and simplified message sending. For your clan system, you might want to implement a queue system to manage message sending and reaction adding separately. This could help isolate the issue and prevent runtime errors. Also, double-check your bot’s permissions in the Discord server settings. Sometimes, insufficient permissions can cause unexpected errors when trying to send messages or add reactions.

I’ve been through this exact headache with Discord bots. One thing that worked for me was using a try-except block when sending messages. It helps catch those pesky runtime errors and gives you more info on what’s going wrong. Also, make sure your bot token is correct and up-to-date. I once spent hours debugging only to realize my token had expired.

For adding reactions, have you looked into using discord.py’s wait_for() method? It lets you wait for the message to be sent successfully before trying to add reactions. Might solve your webhook issue.

Lastly, double-check your bot’s intents. Sometimes you need to enable specific intents in the Discord Developer Portal for certain actions to work. Hope this helps!