Discord.py - Previous function affects the next function

130 views Asked by At

I am trying to make a discord bot using Python and I want to make it so not everyone can mention @everyone or when they do the message will be deleted immediately, but then I have another code ($snipe) which doesn't work until I delete it, and after I do, it gives me the response! Any help would be appreciated!

@client.event
async def on_message(message):
    xall = "@everyone"
    
    role1 = discord.utils.get(message.guild.roles, name = "Owner")
    role2 = discord.utils.get(message.guild.roles, name="Mod")
    roles = role1 or role2

    if xall in message.content:
        if roles in message.author.roles:
            pass
        else:
            await message.delete(message)


#Fun
       
#/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@client.command()
async def snipe(ctx):
    await ctx.send("Aight, imma go snipe!")

@client.command()
async def slap(ctx, members: commands.Greedy[discord.Member], *, reason='no reason'):
    slapped = ", ".join(x.mention for x in members)
    await ctx.send('{} just got slapped for {}'.format(slapped, reason))
1

There are 1 answers

3
Joshua Nixon On
import discord

from discord.ext import commands

client = discord.Client()

@client.event
async def on_message(msg):  
    owner = discord.utils.get(msg.guild.roles, name="Owner")
    mod = discord.utils.get(msg.guild.roles, name="Mod")

    roles = (owner, mod)

    if msg.mention_everyone:
        if not any(r in msg.author.roles for r in roles):
            await msg.delete()

client.run(TOKEN)

I have just ran this, and this works as expected. Removes the message if needed.