[英]How to mention a sender of a command? discord.py
我創建了一個超級簡單的.report <person>
命令。 我有它,所以當有人輸入時它會被發送到某個頻道。 我想要做的是讓它顯示報告其他用戶的用戶的姓名。 我不知道該怎么做。 有誰知道最好的方法?
@bot.command()
async def report(*, message):
await bot.delete(message)
await bot.send_message(bot.get_channel("479177111030988810"), message)
您可以執行以下操作,在其中獲取上下文(ctx),並從中獲取消息的內容及其作者
@bot.command(pass_context=True)
async def report(ctx):
await bot.delete_message(ctx.message)
report = f"\"{ctx.message.content[8:]}\" sent by {ctx.message.author}"
await bot.send_message(bot.get_channel("479177111030988810"), report)
您可以使用ctx.author.mention
來提及用戶。 mention
屬性( 在此處記錄)返回一個字符串,您可以在send
的參數中使用該字符串。
用法示例:
@bot.command("hello", help="Learn about this bot")
async def hello(ctx: discord.commands.Context):
await ctx.send(f"Hi {ctx.author.mention}! I'm a bot!")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.