【问题标题】:TypeError: 'coroutine' object is not callableTypeError:“协程”对象不可调用
【发布时间】:2019-12-06 00:18:29
【问题描述】:

我试图让我的机器人创建一个服务器(公会),但我遇到的问题是它说它没有在等待,即使我让它等待。

我试过等待它

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

【问题讨论】:

标签: python async-await discord.py coroutine


【解决方案1】:

您正在尝试将Client.create_guild 用作装饰器,但事实并非如此。

你的代码相当于

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

start_creation = client.create_guild(temp)

所以start_creation是一个协程对象,它是可等待但不可调用的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-01
    • 2022-06-29
    • 1970-01-01
    • 2018-12-25
    • 2021-04-15
    • 2011-10-01
    • 2020-11-10
    • 2017-09-09
    相关资源
    最近更新 更多