【发布时间】:2021-09-26 04:20:17
【问题描述】:
编辑:我已经通过使用另一种方法修复了代码,不过感谢其他有用的答案!
我正在发出一个说命令,它只是接收用户的消息并通过机器人重复它。但是它可以被滥用来ping每个人等等。所以我想这样做,当用户不是管理员时,它会检查@everyone或@here的消息。然后它说您无法 ping 所有人,并使用自定义命令对输出“您无法 ping 所有人”消息做出反应。 顺便说一句,它也在齿轮中。该命令在使用时不会引发任何控制台错误,而是不执行任何操作。 编辑:我已经通过使用另一种方法修复了代码,不过感谢其他有用的答案!
@commands.command()
async def say(self, ctx, *, message):
await ctx.message.delete()
if not ctx.message.author.guild_permissions.administrator:
if "@everyone" in message or "@here" in message:
antiping = "You can't mention everyone through me!"
await ctx.send(antiping)
await antiping.add_reaction(emoji=':Canteveryone:890319257534103603')
return
else:
await ctx.message.delete()
await ctx.send(message)
【问题讨论】:
-
我认为你的命令的问题可能是如果作者不是管理员,并且消息不包含
@everyone,它不会做任何事情。您需要为if "@everyone" in message..语句编写else语句。此外,您应该删除最后一个else块中的ctx.message.delete(),因为您已经事先删除了代码中的消息。 -
哦也可以考虑使用clean_content:discordpy.readthedocs.io/en/master/ext/commands/…
标签: python discord discord.py