Discord.py 如何让我的机器人在重复用户参数时不ping 所有人

时间:2021-04-21 20:29:05

标签: python discord.py

我正在尝试创建一个重复用户所说内容的命令,但是当人们在他们的消息中输入 @everyone ping 时,bot 会 ping 所有人。 我的代码:

@bot.command()
async def say(ctx, *, arg):
  everyone = ctx.message.guild.default_role
  if arg == everyone:
    await ctx.send(arg.replace('@every-no'))
  await ctx.send(arg)

1 个答案:

答案 0 :(得分:0)

Discord 有一个实用功能可以避免提及! discord.utils.escape_mentions(text) 看看吧!

您还可以在发送消息时使用 AllowedMentions 对象。

allowed = discord.AllowedMentions.all() # Make all mentions escaped. You can always change.
await ctx.send(arg, allowed_mentions=allowed)