python - 使用 Python 通过用户 ID 发送不和谐的直接消息
问题描述
我制作了一个不和谐的机器人,它通过用户 ID 发送消息。
问题是我无法运行这个机器人。代码是:
import discord
from discord.ext import commands
import json
bot = commands.Bot(command_prefix='?')
@bot.event
async def on_ready():
print(' [!] messaging..\n')
with open("ids.json", "r") as file:
data = json.load(file)
indx = 0
for i in data:
indx += 1
member = await bot.fetch_user(i)
try:
await member.send("message to send")
print(f" [+] Sent message {indx} / {len(data)}")
except Exception as e:
print(f" [!] {e}")
print(" [+] Done")
bot.run("bot token", bot = False)
我得到的错误是:
Ignoring exception in on_ready
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 17, in on_ready
member = await bot.fetch_user(i)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 1384, in fetch_user
data = await self.http.get_user(user_id)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 250, in request
raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10013): Unknown User
解决方案
错误 404 表示未找到。
因此,在不和谐中,错误 404 表示未找到用户。
所以检查你的用户ID,然后再试一次
推荐阅读
- reactjs - 如何使用 useState 钩子和 Typescript 初始化状态
- ios - 从 Testflight 安装同一应用程序的不同构建版本时,UserDefaults 正在消失
- symfony - symfony 如何为 php 翻译读取语言环境
- hyperledger-fabric - 在 HYPERLEDGER Fabric 的链码中调用合约形成另一个合约
- azure - 无法在 Azure DevOps 中删除或重命名 wiki 文章
- inno-setup - 使用 SC 在 Inno Setup 中设置服务属性
- postgresql - 将 Json 数组插入 Postgresql 时出错
- swift - Swift 5.1:如何在一种类型的集合上调用 map 并返回另一种不同类型的集合?
- angular - 升级到 Angular 8 后未定义 JustGage
- html - 在 html 中执行两个 css 翻译时闪烁