0
votes

I am trying to connect my bot to a voice channel using discord.py but it is not working to me so well... any help on how I can improve that?

    @bot.command(pass_context=True)
    async def join(ctx):
        channel = ctx.author.voice.channel
        await bot.join_voice_channel(channel)

Error :

    Ignoring exception in command join:
    Traceback (most recent call last):
      File "C:\Users\matan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\core.py", line 85, in wrapped
        ret = await coro(*args, **kwargs)
      File "C:/Users/matan/Desktop/python/discord bot 1/Main.py", line 926, in join
        await bot.join_voice_channel(channel)
    AttributeError: 'Bot' object has no attribute 'join_voice_channel'

I also have this code :

    @bot.command()
    async def play(ctx, url : str, channel = discord.VoiceChannel):
        await channel.connect()

It has no errors - it is just doing nothing...

1
I think you mean channel: discord.VoiceChannel, not an assignment =Joshua Nixon

1 Answers

0
votes

To join a channel you use await VoiceChannel.connect()

So for your example it would be

@bot.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()

Also pass_context is deprecated afaik.

For your second example

@bot.command()
async def play(ctx, url: str, channel: discord.VoiceChannel):
    await channel.connect()

There is just a typo I guess, you have to use a : to declare the arguments type.