发送朋友请求

时间:2018-08-26 17:53:03

标签: python discord discord.py discord.py-rewrite

想知道如何以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

1 个答案:

答案 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来避免不必要的阻塞。