hoojpop
hoojpop

Reputation: 115

How to fix the error with the execution of the command for the bot?

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

Answers (1)

chluebi
chluebi

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

Related Questions