#Trouble with handling events

1 messages · Page 1 of 1 (latest)

ruby compass
#

Hello, I'm a little stupid, but can anyone explain me why this code doesn't works? What should I return at the end of handle-method? Code runs properly and there is no exceptions, but bot aren't sending a message.

fading carbon
#

You need to add async to your method signature and await that asynchronous method (SendMessageAsync())

#

You won't need to return anything if the return type is Task and you have async in your method signature (and you have code which requires await)

ruby compass
#

thank you

#

now i have an exception

fading carbon
#

it's telling you the problem

#

you're not checking to see if the message is empty

ruby compass
#

message wasn't empty

#

at the deleting moment

#

why the exception invokes

#

message in discord can't be empty

fading carbon
#

yes, they can

ruby compass
#

how

fading carbon
#

if you do not have the message content intent, discord will not send the text content of the message to your bot

#

hans tag message content

knotty jayBOT
# fading carbon hans tag message content

Help, my bot stopped receiving message content!
Help, my bot stopped responding to text-based commands!
As of September 1st 2022, Discord started requiring message content intent for bots that want to read message content. This is a privileged intent!

If your bot has under 100 guilds, all you have to do is flip the switch in the developer dashboard.
If your bot has over 100 guilds, you'll need approval from Discord's end.

However, Discord urges you to use their new Slash Command API, so do make sure to see if that is a viable option for you.

More info:
https://support-dev.discord.com/hc/en-us/articles/4404772028055-Message-Content-Privileged-Intent-FAQ

fading carbon
#

In short: enable the intent in the developer dashboard, then add the intent to your DiscordConfiguration

ruby compass
#

are u about that?

fading carbon
#

yes

#

it must also be specified in your config too

ruby compass
#

uhhhhhh

#

still an error

fading carbon
#

It's also likely the message was not cached by the bot

#

Discord will not send the deleted message when it sends that event

#

If your bot was not online when the message was originally sent, it will not have the message in the cache

ruby compass
#

lol

#

no

#

it was new message

#

it had been written after bot was started

fading carbon
#

Dunno what to tell you then

#

To avoid that exception, check if the content is empty before sending a message.

ruby compass
#

but content is empty in every message

#

wtf

#

is it discord trouble?

#

I think bot have no access to message content

#

because exception invokes also when I'm editing a message

ruby compass
#

solved

#

I'm added intents after starting bot

#

that was exception's reason