Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py-上一个函数影响下一个函数_Python_Python 3.x_Discord_Discord.py - Fatal编程技术网

Python Discord.py-上一个函数影响下一个函数

Python Discord.py-上一个函数影响下一个函数,python,python-3.x,discord,discord.py,Python,Python 3.x,Discord,Discord.py,我正在尝试使用python制作一个discord机器人,我想这样做,这样就不会让每个人都提到@everyone,或者当他们提到@everyone时,消息会立即删除,但是我有另一个代码($snipe),它在我删除它之前不起作用,在我删除它之后,它会给我响应!任何帮助都将不胜感激:) 我刚刚运行了这个,它的工作原理和预期的一样。如果需要,删除邮件。您可以在您的服务器设置中禁用@everyone Indicationsserver@JoshuaNixon是的,我知道,但我想这样做,以便删除邮件!:/如

我正在尝试使用python制作一个discord机器人,我想这样做,这样就不会让每个人都提到@everyone,或者当他们提到@everyone时,消息会立即删除,但是我有另一个代码($snipe),它在我删除它之前不起作用,在我删除它之后,它会给我响应!任何帮助都将不胜感激:)


我刚刚运行了这个,它的工作原理和预期的一样。如果需要,删除邮件。

您可以在您的服务器设置中禁用@everyone Indicationsserver@JoshuaNixon是的,我知道,但我想这样做,以便删除邮件!:/
如果没有(message.author.roles中的r在[role1,role2]):等待message.delete(message)
我认为您的问题是
role1或role2
返回的是布尔值,而不是您希望的列表。此外,您还可以使用
消息。提及所有人
检查消息是否提及所有人。@JoshuaNixon此操作不起作用:(我尝试了此操作,但此操作甚至没有删除提及内容,$snipe命令只有在删除后才起作用:(我认为您需要添加更多信息,例如您使用的是selfbot、client、bot吗?我的答案正好符合您使用
Discord.client bot
的要求。我将尝试明天修复它,因为我确实很累,而且已经很晚了,xd。无论如何,感谢您的帮助:)
@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))
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)