【问题标题】:TypeError: 'ExistingCountries' object is not callable?, Discord.py Rewrite [closed]TypeError:'ExistingCountries'对象不可调用?,Discord.py重写[关闭]
【发布时间】:2021-01-19 01:14:12
【问题描述】:

我正在尝试在一体式机器人的 discord.py 中创建一个随机国家/地区命令,但是我收到错误 TypeError: 'ExistingCountries' object is not callable。 Pycountry 被导入到机器人中

import discord
import random
import asyncio
import time
import youtube_dl
import functools
import itertools
import math
import sys
import traceback
import pycountry
import datetime
from functools import partial
from youtube_dl import YoutubeDL
from async_timeout import timeout
from discord.ext import tasks, commands

bot = commands.Bot(command_prefix = 'is!')
bot.remove_command('help')

@bot.command(pass_context=True)
async def randomcountry(ctx):
    c = pycountry.countries()
    await ctx.send(f'{random.choice(c)}')```

【问题讨论】:

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


    【解决方案1】:

    你需要把它列成一个列表:

    random.choice(list(pycountry.countries)).name
    

    如需进一步参考,您可以阅读文档here

    【讨论】:

    • @DTOG 我将其编辑为正确的实现:抱歉出现问题!如果答案有帮助,您可以在几分钟内单击绿色复选标记,以便其他用户知道针对您的问题的正确实施。感谢您的提问!
    猜你喜欢
    • 2021-01-12
    • 2020-11-20
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多