【问题标题】:Discord.py - Previous function affects the next functionDiscord.py - 上一个函数影响下一个函数
【发布时间】:2020-04-30 16:58:11
【问题描述】:

我正在尝试使用 Python 制作一个不和谐的机器人,我想制作它,所以不是每个人都可以提及@everyone,或者当他们这样做时,消息将被立即删除,但是我有另一个代码 ($snipe),它没有在我删除它之前无法工作,在我删除它之后,它会给我回应!任何帮助将不胜感激!

@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))

【问题讨论】:

  • 您可以在服务器的服务器设置中禁用@everyone 提及
  • @JoshuaNixon 是的,我知道,但我想这样做,以便删除消息! ://
  • if not any(r in message.author.roles for r in [role1, role2]): await message.delete(message)
  • 我认为您的问题是 role1 or role2 返回一个布尔值,而不是您希望的列表。此外,您可以使用message.mention_everyone 来检查消息是否提到了所有人。
  • @JoshuaNixon 这没用 :(

标签: python python-3.x discord discord.py


【解决方案1】:
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)

我刚刚运行了这个,它按预期工作。如果需要,删除消息。

【讨论】:

  • 我试过这个,但是这个甚至没有删除提及,并且 $snipe 命令只有在我删除它之后仍然有效:(
  • 我认为您需要添加更多信息,例如您使用的是自我机器人、客户端还是机器人?我的回答完全符合您使用Discord.Client bot 的要求。
  • 我明天会尝试修复它,因为我真的很累而且很晚了,xd。不管怎样,谢谢你的帮助:)
猜你喜欢
  • 2010-12-16
  • 2015-12-29
  • 1970-01-01
  • 1970-01-01
  • 2012-03-21
  • 1970-01-01
  • 2015-08-15
  • 1970-01-01
  • 2020-04-14
相关资源
最近更新 更多