【发布时间】:2021-05-08 04:07:05
【问题描述】:
我是编码新手。我希望我的机器人使用随机消息响应用户命令,其中他们的姓名在消息中的位置会有所不同。
@bot.command()
async def hello(ctx):
responses = ["hi, {ctx.author.name}!",
"{ctx.author.name}, how are you?",
"Good day, {ctx.author.name}, how's the weather there?"]
await ctx.send(f'{random.choice(responses)}')
这是我部署机器人时发生的情况:
/hello
hi, {ctx.author.name}!
/hello
{ctx.author.name}, how are you?
但是,例如,我希望机器人以用户名进行响应
/hello
hi, Bob!
/hello
Bob, how are you?
我将非常感谢任何帮助!
【问题讨论】:
标签: python discord bots discord.py