#implement MessageReceived in each command module?

1 messages · Page 1 of 1 (latest)

lofty oar
#

i would like to have the MessageReceived event from DiscordSocketClient be handled by each command module, but im not sure how to have the services be passed into them because some eventhandlers modify user stats in a database

bonus if i can get the events subscribed automatically if a module implements IMessageReceiver (attached is my current implementation but it fails after using the module's commands as it complains the ServiceProvider has been disposed)

blazing trail
#

What's your use case of implementing MessageReceived event in command modules ?

astral python
#

I assume what you actually want is some sort of wait for message event in the command 🤔

lofty oar
lofty oar
astral python
#

that's not going to work

#

modules are transient

#

what you want is some sort of service

lofty oar
#

so you're saying i can only keep it in one place

astral python
#

u can do multiple services if you want

#

but you can't keep it in the same place as your command

lofty oar
#

it's because the module is instantiated every time a command is run right

astral python
#

yes

lofty oar
#

and the service provider is disposed after each run

#

ok that makes sense

#

damn in the python library each cog is able to have its own on_message event

astral python
#

the logic doesn't seem tied to a command/module though

#

besides probably enabling/disabling it

#

so there doesn't seem to be an actual need to have it there

#

which is why i assumed you were like waiting for a response to a command or something

#

if you are just processing all messges why add it to a module?

lofty oar