#Thread regarding the interactions

1 messages · Page 1 of 1 (latest)

prisma yacht
#

First message.

hushed ferry
#

Second message

#

😉

#

How do you handle your events? So how is the interactioncreate event handled in this case

#

Is it in your main file as client.on(interactioncreate)?

prisma yacht
hushed ferry
#

Or in seperate files

prisma yacht
#

This is the interactionCreate on this bot

clear light
hushed ferry
#

Ah okay

prisma yacht
#

No it's in a different file

hushed ferry
#

Then that's not the issue

clear light
hushed ferry
#

Apologies for the confusion

prisma yacht
#

When using the "lancerunscenario" command, it calls the function in another file

hushed ferry
#

What is that function?

prisma yacht
hushed ferry
#

Yeah that shouldnt cause issues

prisma yacht
#

(To give some context, the bot is a library bot, opening various gamebooks)

hushed ferry
#

Is your bot in many servers?

#

Do many ppl put reactions on msgs there?

prisma yacht
#

So with the slash command, you select a book, in this case "Labyinthe de Sang"

hushed ferry
#

Wait let's do it easy

prisma yacht
hushed ferry
#

Put this in the messagereactionadd event

#

Console.log(1)

prisma yacht
#

It's only in one guild, and there are no reactions atm

clear light
# prisma yacht

you should put that messageReactionAdd event in this file as events inside events will make it loop

hushed ferry
#

Wait no that won't work

#

You could make a counter

#

In the event handler to count how many times its been called

#

That way you can see how many times the event was emitted in your console

#

You could put

let counter = 0

Before the event

prisma yacht
hushed ferry
#

And in the event console.log(counter) and in the next line counter++

hushed ferry
# prisma yacht

Also please make sure not to push slash commands at every reboot

#

There's a limit of 100 global and 100 guild commands per day, it'll get you rate limited. It's annoying

#

For you*

prisma yacht
#

Didn't know!

#

I corrected it

hushed ferry
#

Epic! Just triggering with a command or a seperate script does the trick

#

I like to use a command, but many ppl use seperate scripts as you need to reload the bot anyways to add your command handler for the new command into the working bot anyways

prisma yacht
#

This is the number of times every handler is called

hushed ferry
#

Hmm and this all triggers when you boot the bot and then only click a reaction

#

Can you send your entire main file

prisma yacht
#

the first addMessageReaction entered isn't triggered when the bot reacts

#

both are triggered when I click

hushed ferry
#

Hmm but you got the type guard now so that's expected

prisma yacht
hushed ferry
#

The client.on needs to be in another file

#

Because it'll work always globally

#

So you can just add it in main file

clear light
# prisma yacht

your messageReactionAdd event needs to be in the file with your interactionCreate event (maybe below that event?)

hushed ferry
#

Yup

#

Unless your events get seperated into files

prisma yacht
#

wow

#

That completely breaks the way I architectured this one

hushed ferry
#

I hate how djs explains this crap to new users

prisma yacht
#

Gimme a second to figure out what it means

hushed ferry
#

Okay

prisma yacht
#

I mean, I fully understand what's going on

#

Just figuring out the implications in this case

hushed ferry
#

Basically event handlers occur once in the main file and listen to events being emitted from. The client

#

Okay

#

Feel free to ask if you need anything

clear light
#

by the way, if you don't like a whole spaghetti of event emitters, then you can create an event handler, which spans your events on multiple files (like your command handler). this makes it more readable

prisma yacht
#

That's helpful I'll think about that

pale trellisBOT
hushed ferry
#

Yea that's what I super hate but it does help for some

prisma yacht
#

I'll try to rethink the code and will keep the thread open in the meantime

#

Thanks a lot to both of you

hushed ferry
#

Yea def do!

#

Anytime!

clear light
#

no problem!

prisma yacht
#

Well it was fast.

#

This is the code in the main file:

hushed ferry
#

Now it'll fire once

prisma yacht
#

My understanding was that messageReactionAdd was global. So if I started the bot, it would print a "Hello buddy" every time I clicked a reaction in the guild?

hushed ferry
#

For each reaction

prisma yacht
#

But it absolutely doesnt

hushed ferry
#

Hmm what does it do

prisma yacht
#

Nothing

#

It isn't called

hushed ferry
#

Your client is constructed in that file?

#

That's very weird

prisma yacht
#

Yes

hushed ferry
#

And interactions still work?

prisma yacht
#

interaction does work normally

hushed ferry
#

That looks mighty fine

#

No typos in the event name messagereactionadd?

#

Don't see any

prisma yacht
#

Just c/c'd from the other file where it looped

#

That's pretty confusing

hushed ferry
#

That's very weird

#

I can't hop on my pc atm to check

prisma yacht
#

Nah nah it's all good

#

I'll try to figure it out

#

And will let you know if I find an explanation

hushed ferry
#

Hold up

prisma yacht
#

Yeah?

hushed ferry
#

Did you send a new message

#

With a reaction

#

Or an old one

prisma yacht
#

Old one

hushed ferry
#

Send a new one

#

The message is uncached

#

After a reboot

prisma yacht
#

Works

hushed ferry
#

So you'd need to fetch the message for it to work on the old one

prisma yacht
#

wow

hushed ferry
#

I'd suggest using buttons over reactions

prisma yacht
#

Yep definitely but

#

Aren't buttons only used to reply to a command?

hushed ferry
#

They always emit interactioncreate no matter if the message was sent 20 years ago

hushed ferry
#

They emit the same event as a command

prisma yacht
#

I would like to print buttons afgter a messge to let users choose between options

#

OKOK

hushed ferry
#

You can add buttons like you have the reactions now

prisma yacht
#

I'll check the doc for the buttons

#

Thanks!

hushed ferry
#

No problem!

#

It's much easier to handle

prisma yacht
#

Yeah definitely seems like it

hushed ferry
#

And can work with custom ids, which saves you the pain of dealing with all the different reactions

#

If you need, give me a ping here or hit me up in dms

prisma yacht
#

Sure thing, really appreciate the help!