Closed rn4n closed 3 years ago
Split the code in separated cogs also duplicate the event handling:
#bot/first_cog.py
from twitchio.ext import commands
class FirstCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.event()
async def event_message(self, message):
if message.echo:
return
print("Hello from first cog")
def prepare(bot):
bot.add_cog(FirstCog(bot))
#bot/second_cog.py
from twitchio.ext import commands
class SecondCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.event()
async def event_message(self, message):
if message.echo:
return
print("Hello from second cog")
def prepare(bot):
bot.add_cog(SecondCog(bot))
# __main__.py
from twitchio.ext import commands
bot = commands.Bot(
token="...",
prefix="...",
initial_channels=["..."],
)
bot.load_module("bot.first_cog")
bot.load_module("bot.second_cog")
bot.run()
After any message on twitch chat:
Hello from first cog
Hello from first cog
Hello from second cog
Fixed as of version 2.0.4
. Thanks for the issue 👍
If you find any bugs in version 2.0.4
please let me know
Describe the bug I'm having behavior that I believe to be incorrect on creating of cogs. When I create more than one class inheriting from Cog, even though I don't instantiate it, it's being executed by the bot. And when I use the class, it seems to me that the bot is handling the same event more than once. Perhaps with the code below it will be easier to understand.
Are you using TwitchIO within a Discord Bot? No
What commit of TwitchIO are you using?
To Reproduce Steps to reproduce the behaviour:
When I type something on Twitch's chat, the console shows me:
If you uncomment the
bot.add_cog(SecondCog(bot))
part and execute:Expected behaviour Only the events of the added cog should work. Do not call twice the same event in different cogs
(please complete the following information):