python - 如何让 Discord Bot 说出消息的作者
问题描述
在这种情况下,如何让机器人响应“Hello”,然后是使用 .hello 命令的人的姓名?
这就是我到目前为止所拥有的。
@client.command(pass_context = True)
async def hello(ctx):
author = ctx.message.author.name
await ctx.send("Hello", author, "!")
解决方案
您应该使用 f 字符串。你能做的是
@client.command()
async def hello(ctx):
await ctx.send(f'hello {ctx.author.name} !')
另外,如果您想要执行命令的用户,您也可以这样做ctx.author
。不需要ctx.message.author
。
推荐阅读
- rust - How do I conditionally execute code only when an Option is None?
- java - Ubuntu 服务器上的打开文件限制
- mongodb - MongoDB - 创建一个布尔字段来测试某些子字段的存在
- jquery - 旋转表格行的图标点钟
- javascript - 使用javascript中的映射跳过数组中的元素
- mysql - MySQL 8 和 MySQL 5.7 的区别
- wxpython - 加载 Gif 只有在完成所有后台任务后才会显示,Wxpython AnimationCtrl
- html - img 标签 src 问题
- javascript - 循环地图时JavaScript堆内存不足?
- python - 迭代 Pandas DataFrame 并插入行的最快方法