Discord.py 发送好友请求

Discord.py send friend requests

想知道如何使用 id.txt 作为 infile 发送好友请求。 我的代码看起来像这样但不起作用

@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以避免不必要的阻塞。