想知道如何以id.txt作为文件名发送朋友请求。 我的代码看起来像这样,但是不起作用
@client.event
async def on_ready():
with open("id.txt") as infile:
for line in infile:
id = int(line)
user = await client.get_user_info(id)
try:
time.sleep(.305)
await user.send.friend_request
except (discord.Forbidden, discord.HTTPException):
continue
答案 0 :(得分:1)
正确的协程是User.send_friend_request
,您必须调用它。
from asyncio import sleep
@client.event
async def on_ready():
with open("id.txt") as infile:
for line in infile:
id = int(line)
user = await client.get_user_info(id)
try:
await sleep(.305)
await user.send_friend_request()
except (discord.Forbidden, discord.HTTPException):
continue
您还应该使用asyncio.sleep
来避免不必要的阻塞。