TypeError: 'ExistingCountries' object is not callable?, Discord.py Rewrite
TypeError: 'ExistingCountries' object is not callable?, Discord.py Rewrite
我正在尝试在 discord.py 中使用一体化机器人创建随机国家/地区命令,但是我收到错误类型错误:'ExistingCountries' 对象不可调用。 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
我正在尝试在 discord.py 中使用一体化机器人创建随机国家/地区命令,但是我收到错误类型错误:'ExistingCountries' 对象不可调用。 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