Discord Py 用户在消息中提及

时间:2021-01-28 20:34:09

标签: python discord.py

所以我目前正在尝试让我的不和谐机器人收到一个提及的命令,ping 提到的人并说“闭嘴”。代码运行但它ping 人,然后说闭嘴。我需要一些帮助来尝试将这两个部分合并为一条消息而不是 2 条。

async def quiet(ctx, user : discord.Member):
  await ctx.channel.send(user.mention)
  await ctx.channel.send("shut up")

3 个答案:

答案 0 :(得分:2)

await ctx.channel.send(user.mention + "shut up") 应该这样做

答案 1 :(得分:0)

你可以尝试这样的事情:

async def quiet(ctx, user : discord.Member):
  message = user.mention + "shut up"
  await ctx.channel.send(message)

让我知道它是否有效!

答案 2 :(得分:0)

您可以尝试使用 f 字符串来执行此操作,同时使用大括号覆盖“提及”部分。

async def quiet(ctx, user : discord.Member):
    await ctx.channel.send(f"{user.mention} shut up!")
    

几乎可以用于任何事情,例如:

在下图中,如果未指定数字,我将使用以下命令作为清除命令:

if limit is None:  #limit is an argument here, that is amount of messages user wants to delete
      return await ctx.send(f"{ctx.author.mention} Please specify the number of messages you want to delete!", delete_after = 3)  #this sends a message to specify the amount of message the user desires to delete while mentioning them (the author is the term for the person who triggered the command)

enter image description here

相关问题