TypeError:“协程”对象不可调用

时间:2019-07-28 11:49:38

标签: python async-await discord.py coroutine

我正在尝试让我的机器人创建服务器(行会),并且即时通讯出现问题,即使我将其等待也没有等待。

我试图等待它

import discord, random, string, asyncio
from discord.ext import commands

def randomString(stringLength=10):
    letters = string.ascii_lowercase
    return ''.join(random.choice(letters) for i in range(stringLength))


Token = ""
client = discord.Client()

print("-----------------------------------")
print("|             Choices             |")
print("|       (1) Token Banner          |")
print("-----------------------------------")

Choice = input("Which choice would you like to choose?: ")

if Choice == "1":
    Token = input(str("What token would you like to get banned?: "))

    @client.event
    async def on_ready():
        print("Logged in as: %s" % Token)

    @client.create_guild
    async def start_creation():
        await client.create_guild(randomString(10), region=None, icon=None)

    asyncio.run(start_creation())


    client.run(Token, bot=False)

预期:创建具有随机字符串,无区域,无图标的服务器 实际结果:协程问题 错误

Traceback (most recent call last):
  File "app.py", line 31, in <module>
    asyncio.run(start_creation())
TypeError: 'coroutine' object is not callable
sys:1: RuntimeWarning: coroutine 'Client.create_guild' was never awaited

1 个答案:

答案 0 :(得分:0)

您正在尝试使用Client.create_guild作为修饰符,事实并非如此。

您的代码等同于

async def temp():
    await client.create_guild(randomString(10), region=None, icon=None)

start_creation = client.create_guild(temp)

因此start_creation是一个协程对象,可以等待但不能调用。