我的代码:
a = 1
b = 600
@client.command()
async def iponergoopelda(ctx):
for line in range(a , b):
with open("id users2.txt") as f:
data = f.readlines()
for line in data:
user = await client.fetch_user(int(line.strip()))
await user.send('hey')
print('Отправлено')
这不会在 dm 中发送消息,因为 dm 出错,
Ignoring exception in command iponergoopelda:
Traceback (most recent call last):
File "C:\Users\Никитос\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Никитос\Desktop\Nukebot.py", line 51, in iponergoopelda
await user.send('hey https://discord.com/api/oauth2/authorize?client_id=815193692432367646&permissions=2214068032&scope=bot')
File "C:\Users\Никитос\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\abc.py", line 883, in send
channel = await self._get_channel()
File "C:\Users\Никитос\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\user.py", line 697, in _get_channel
ch = await self.create_dm()
File "C:\Users\Никитос\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\user.py", line 725, in create_dm
data = await state.http.start_private_message(self.id)
File "C:\Users\Никитос\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\http.py", line 247, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50007): Cannot send messages to this user
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Никитос\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Никитос\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Никитос\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50007): Cannot send messages to this user
在文档中我有 ids 人,我尝试使用 3ids 工作,但使用 200 ids 不起作用。 我不知道是怎么做的,也许可以尝试一下。
答案 0 :(得分:1)
正如我在评论中所说的
用户只是禁用了 dm,然后无法发送消息。你可以放一个 try/except 块
a = 1
b = 600
@client.command()
async def iponergoopelda(ctx):
for line in range(a , b):
with open("id users2.txt") as f:
data = f.readlines()
for line in data:
user = await client.fetch_user(int(line.strip()))
try:
await user.send('hey')
except:
pass
print('Отправлено')