python - TypeError : 'ExistingCountries' object is not callable? , Discord.py 重写

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

<分区>

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

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)}')```

最佳答案

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

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

如需进一步引用,您可以阅读文档 here

关于python - TypeError : 'ExistingCountries' object is not callable? , Discord.py 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64187146/

相关文章:

python - conv2d 之后的 PyTorch CNN 线性层形状

python - 如何使用 python win32com.client 在 Excel 中添加折线?

python - 使用 Peewee 处理数据库断开连接

javascript - 获取 Discord.JS 机器人的正常运行时间

python - 官方 Django 教程第 1 部分 : RuntimeError: maximum recursion depth exceeded in cmp

python - 在句子标记化之前删除 python 中的多个\n

python - 那是奎因还是什么?

python - 重新排列数据帧的索引以将字符串移至顶部

javascript - 角色 Discord.js(在嵌入中打印角色)

javascript - Discord Webhook 消息无法发送