python - 如何通过嵌入页脚向具有 ID 的用户发送消息?
问题描述
我正在尝试通过消息 ID 获取用户 ID;我要向其发送 DM 的用户 ID 位于嵌入的页脚中。我正在使用此代码:
msg = await ctx.channel.fetch_message(id)
id2 = int(msg.embeds[0].footer.text)
print(type(id2))
await ctx.send(id2, hidden=True)
# Everything works fine ^
# Everything breaks below
user = client.get_user(id2)
print(type(user))
await ctx.send(user, hidden=True)
await user.send("IT WORKED!!!")
我添加了一些调试代码,当它尝试将其转换为user = client.get_user(id2)
. 它把它变成虚无;我在函数中看到了这一点type()
,并且在错误中:
An exception has occurred while executing command `answer`:
Traceback (most recent call last):
File "/Users/dante_nl/Library/Python/3.8/lib/python/site-packages/discord_slash/client.py", line 1185, in invoke_command
await func.invoke(ctx, **args)
File "/Users/dante_nl/Library/Python/3.8/lib/python/site-packages/discord_slash/model.py", line 209, in invoke
return await self.func(*args, **kwargs)
File "/Users/dante_nl/Library/Mobile Documents/com~apple~CloudDocs/Ask/bot.py", line 105, in _answer
await ctx.send(user, hidden=True)
File "/Users/dante_nl/Library/Python/3.8/lib/python/site-packages/discord_slash/context.py", line 239, in send
resp = await self._http.post_followup(base, self._token, files=files)
File "/Users/dante_nl/Library/Python/3.8/lib/python/site-packages/discord/http.py", line 254, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message
我不确定它为什么这样做,它从嵌入的页脚获取 ID,将其转换为数字,但它无法将其转换为用户并将 DM 发送给该用户。
提前致谢!
注意:我正在使用斜杠命令,不确定这是否有任何区别。
解决方案
您可以使用:
await client.fetch_user(id2)
如果这不起作用,那么可能 id2 不是有效的用户 ID。
推荐阅读
- javascript - 使用 Puppeteer 查找以某个单词开头的所有 ID
- javascript - 遵循 github 示例时,google-spreadsheet.js (npm) 不起作用
- node.js - 将点几何添加到 Postgresql
- windows - 需要使用powershell以相同的本地用户/密码登录多个IP无提示
- web-scraping - 用于计算股票新闻的网络抓取
- c - 合并排序链表给出分段错误
- reactjs - 在 JSX/React 中读取连接标识符或路径的值?
- c++ - 如何使用基于范围的循环将向量的元素打印为有序列表
- c# - 如何防止 UI 按钮在每次点击时重置为启动条件?Unity3D
- sql-server-2012 - 如何使用 Entity Framework Core 删除没有外键的相关数据