【发布时间】:2021-09-08 12:59:56
【问题描述】:
我制作了一个不和谐的机器人,它通过用户 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
【问题讨论】:
-
data长什么样子? -
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
标签: python python-3.x discord.py