python - 如何使用 discord.py 让 discord bot ping 用户
问题描述
我正在编写一个不和谐的机器人,对于其中一个命令,我希望机器人 ping 发送命令的用户。我正在使用 python 3.6.6
解决方案
这是一个示例,您可以如何 ping(提及)发送特定消息(命令)的用户:
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
# don't respond to ourselves
if message.author == self.user:
return
if message.content == '$the_ping_cmd':
await message.channel.send('Pinging {}'.format(message.author.mention))
client = MyClient()
client.run('token')
推荐阅读
- php - 在php中解析stdClass对象的字符串
- python - 如何与我从脚本登录的新 shell 交互?
- html - 相对于 div 的覆盖加载程序的问题
- sparql - Sparql 端点与 2 个 Sparql 端点合并
- xamarin - Xamarin 表单 Android 自定义条目渲染器在查看一次后适用于所有条目
- c - 学习 C 中文件的语法
- jenkins - 多分支作业扫描无法发现远程 GitHub 存储库标签
- segue - 无法将图像从 tableViewCell 传递到 viewController
- c# - Linq List.Contains(x => ...) - CS0103 x 在当前上下文中不存在(在 foreach 中)
- firebase - 关于 Firebase 火焰计划存储