python - 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
解决方案
你安装 discord.py 还是 discordbot.py?
discordbot是 discord的扩展, 我猜问题是你使用的包。
尝试 :
$ pip install -U discord.py
如果没有,请确保 .json 文件配置正确
推荐阅读
- pytest - Pytest如何从夹具中获得功能补丁
- linux - 如何在当前目录中保存已排序的文件列表
- javascript - 如何在 dialogflow webhook 中创建上下文并保存参数
- java - 静态导入同一文件中的常量
- node.js - 在部署服务器上部署 nvm 时,Jenkins shell 无法正常工作
- git - 删除 git 远程分支
- symfony - EasyAdmin 选择字段错误 Symfony
- c++ - Do-while 循环不会在条件处停止,负函数也不会正确计算负整数
- java - SOAP JAVA WSDL - 在请求标头中添加一个值
- r - 在 rmarkdown 中创建可编辑的表