python - 向消息中指定的特定用户发送消息,discord.py
问题描述
在我的 discord.py 代码中,我试图设置一个简单的发送消息给消息作者指定的用户。
if message.content.startswith('!hello'):
print("Hello DIRECT MESSAGE")
msg = "Why hello there"
print (message.author)
await client.send_message(message.author, msg)
if message.content.startswith('!poke'):
print("Poke DIRECT MESSAGE")
a = message.content[6:]
print(a)
msg = "Hi there"
await client.send_message(a, msg)
!hello 命令工作正常,但我不知道如何在收到用户 ID 作为字符串后将用户 ID 作为发送消息命令的对象。
解决方案
假设这发生在服务器中,命令调用者和目标都是:
target = discord.utils.get(message.server.members, id=a)
推荐阅读
- c++ - 如何将 std::sqrt 存储在 std::function 中
- pdf - 如何解决 RNFetchBlobNative 的导入类型错误
- php - SOAP 客户端 TypeScript
- javascript - 从对象内部的对象创建一个新数组
- c# - 反序列化时将 Json 信息传递给对象构造函数
- microsoft-graph-api - Excel 是否可以与 Microsoft Graph 共同创作?
- c - 我的过滤器应用程序使用以下代码行对图像产生模糊效果在 C 中给出运行时错误
- powershell - 计算每个文件的字符出现次数(仅限第一行)
- laravel - Laravel 与 Percona DB 冲突,因为表没有主键
- postgresql - 如何在 POSTGREQL 9.6 中创建递归函数?