首页 > 解决方案 > 如何让 Discord Bot 说出消息的作者

问题描述

在这种情况下,如何让机器人响应“Hello”,然后是使用 .hello 命令的人的姓名?

这就是我到目前为止所拥有的。

@client.command(pass_context = True)
async def hello(ctx):
    author = ctx.message.author.name
    await ctx.send("Hello", author, "!")

标签: pythondiscorddiscord.py

解决方案


您应该使用 f 字符串。你能做的是

@client.command()
async def hello(ctx):
    await ctx.send(f'hello {ctx.author.name} !')

另外,如果您想要执行命令的用户,您也可以这样做ctx.author。不需要ctx.message.author


推荐阅读