我正在用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
答案 0 :(得分:0)
您是否安装discord.py或discordbot.py?
discordbot 是 discord 的扩展 我想问题是您使用的包装。
尝试:
$ pip install -U discord.py
如果没有,请确保正确配置了.json文件
答案 1 :(得分:0)
bot.voice_clients
是一个列表。您可以使用ctx.voice_client
if ctx.voice_client is not None: