cronokirby / alchemy

A discord library for Elixir
MIT License
152 stars 34 forks source link

How can I use Events? #102

Closed aramsm closed 3 years ago

aramsm commented 3 years ago

I'm trying to use the Events module, so I can send messages to users when they join my guild.... server, and also I wan't to send messages when they receive a specific role.

I saw the docs about on_member_update and on_guild_update but I'm really confused how it works. In summary, I tried to inspect the args those fun receive, but when I changed my data on the server nothing poped in my console (I built the basics for my bot and put it in a discord server to test). The Cogs command is working fine.

cronokirby commented 3 years ago

The examples in the docs for Alchemy.Events should show all the information you need:

https://hexdocs.pm/discord_alchemy/Alchemy.Events.html#content

The idea is to create a module with the event handlers you want.

Those event handlers will be functions.

Then you use Events.on_...(:function_name) to register a callback

Then you need to do use MyModule after starting the client to register the callbacks

aramsm commented 3 years ago

I got the problem. I was trying to use Cogs and Events in the same module, but this overrides Events.