M
M
mishkafrede20042021-12-17 20:21:28
Python
mishkafrede2004, 2021-12-17 20:21:28

Help with cogs. EN: Help with kogami. Two events not working at the same time?

English: Hello! Don't work two events at the same time.
Ru: Hello! Two events do not work at the same time.

import discord
from discord.ext import commands

banwords = ['free nitro']

class Events(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_message(message):
        await bot.process_commands(message)
        member = message.author
        role = discord.utils.get(member.guild.roles, id = 916301099508576307)
        if role in member.roles:
            return
        elif message.author.bot:
            return
        elif "https://" in message.content.lower():
            print('[Logs:utils] Была обнаружена ссылка! Удаляем!')
            await message.delete()
            await message.channel.send("Ссылки запрещены!")
    
    @commands.Cog.listener()
    async def on_message(message):
        await bot.process_commands(message)
        if message.author.bot:
            return
        elif "free nitro" in message.content.lower():
            print('[Logs: utils] Было обнаружено запрещенное слово! Удаляем!')
            await message.delete()
            await message.channel.send('Был обнаружен банворд, со списком запрещенных слов можно ознакомится в соглашении бота. -Binfo')



    @commands.Cog.listener()
    async def on_message(self, message):
        print(message)

def setup(bot):
    bot.add_cog(Events(bot))


Don't work second event.
The second event does not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
asysprotri, 2021-12-17
@asysprotri

They shouldn't work like that. You can put the code in 1 function.

@commands.Cog.listener()
    async def on_message(message):
        await bot.process_commands(message)
        member = message.author
        role = discord.utils.get(member.guild.roles, id = 916301099508576307)
        if role in member.roles:
            return
        if message.author.bot:
            return
        if "https://" in message.content.lower():
            print('[Logs:utils] Была обнаружена ссылка! Удаляем!')
            await message.delete()
            await message.channel.send("Ссылки запрещены!")
        if "free nitro" in message.content.lower():
            print('[Logs: utils] Было обнаружено запрещенное слово! Удаляем!')
            await message.delete()
            await message.channel.send('Был обнаружен банворд, со списком запрещенных слов можно ознакомится в соглашении бота. -Binfo')
        print(message)

M
mishkafrede2004, 2021-12-18
@mishkafrede2004

Conditional block with free nitro still doesn't work and doesn't throw an error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question