Reputation: 115
I am writing a bot for discords. I decided to implement the command to play the video (music). There is a problem with a following code snippet:
@client.command(pass_context=True)
async def play(ctx, url):
channel = ctx.author.voice.channel
await channel.connect()
server = ctx.message.guild
voice_client = client.voice_clients(server)#< An error occurs here
player = await voice_client.create_ytdl_player(url)
players[server.id] = player
player.start()
Namely: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'list' object is not callable
Upvotes: 1
Views: 338
Reputation: 1829
The error is in the line of
client.voice_clients(server)
Where you are calling the list object client.voice_clients
(calling meaning, you're treating as a function, meaning you're using it with brackets).
To find the voice client of a specific server, do something like the following:
voice_client = discord.utils.find(lambda c: c.guild.id == server.id, client.voice_clients)
The find
command is very useful for exactly this kind of stuff. documentation
Upvotes: 1