>想知道如何发送带有 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
正确的协程是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
以避免不必要的阻塞。