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

hoojpop

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

Lu M

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to fix music playback error for Discord bot?

How to fix this Error "The following arguments are required: command"

My discord bot reached the app command limit. How to fix this?

How can I fix my kick command for my Discord bot?

How to fix the Android error "Background execution not allowed: receiving Intent {...}"

How can I fix the web-dev-server execution error?

Ansible command execution error

discord.py have error in my discord bot how to fix?

How can I fix Discord Bot Keyv [Object Promise] error?

How to fix error: module 'discord' has no attribute 'Bot'

How to fix python discord bot none type error?

How to fix cannot find module error when making discord bot?

How can I fix this error in discord.js bot?

How to fix this error "Syntax Error" while running CLI command

How to fix "Execution Error 429 : ActiveX can't create object" error in VBA

How to fix error "WARNING: test command found but not installed in testenv" for tox?

How to fix 'command not found' error in Databricks when creating a secret scope

How to fix the error in GCP CommandException: "lifecycle" command spanning providers not allowed

How to fix json unmarshal error while executing kubectl patch command?

How to fix the Error: Command errored out with exit status 1

How to fix "PKG_PROG_PKG_CONFIG: command not found" error?

How to fix "line is too long" error given by lint command

How to fix ORA-00933 command not properly ended error

How to fix amplify CLI error : "-bash: amplify: command not found"

How do I fix 'jekyll: command not found' error permanently?

How can I fix “setenv command not found ” error ? (Ubuntu 12.04.4)

How to fix 'Sorry, Something went wrong' error while adding bot channel in Azure bot services

How to fix an offline Discord bot?

How do I fix "Execution failed for task 'compileJava'" error. (Using Intellij Idea and Gradle)