首页 > 解决方案 > discord.ext.commands.errors.CommandInvokeError:命令引发异常:TypeError:'list'对象不可调用

问题描述

我正在用 Python (discordbot.py 0.2.3a3) 为 Discord 编写一个机器人。我需要一个机器人来播放音乐。

import asyncio
import discord
from discord.ext import commands
from discord.ext.commands import bot
bot = commands.Bot(command_prefix='!')
from discord.utils import get
songs = asyncio.Queue()
play_next_song = asyncio.Event()



async def audio_player_task():
    while True:
        play_next_song.clear()
        current = await songs.get()
        current.start()
        await play_next_song.wait()


def toggle_next():
    bot.loop.call_soon_threadsafe(play_next_song.set)

@bot.command(pass_context=True)
async def play(ctx, url):
    if not bot.voice_clients(ctx.message.guild):
        voice = await bot.join_voice_channel(ctx.message.author.voice_channel)
    else:
       voice = bot.voice_client_in(ctx.message.guild)

    player = await voice.create_ytdl_player(url, after=toggle_next)
    await songs.put(player)

bot.loop.create_task(audio_player_task())

当我尝试播放音乐时,我在上面代码的第 25 行收到以下错误:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception:

TypeError: 'list' object is not callable

标签: pythonbotsdiscord.py

解决方案


你安装 discord.py 还是 discordbot.py?

discordbotdiscord的扩展, 我猜问题是你使用的包。

尝试 :

$ pip install -U discord.py

如果没有,请确保 .json 文件配置正确


推荐阅读