What to put in stead of "ctx.voice_client" in "interaction:discord.Interaction"

Viewed 53

Here is code to disconnect the bot from vc. But it shows this error AttributeError: 'Interaction' object has no attribute 'voice_client' I looked at https://discordpy.readthedocs.io/ and tried to add it manually but it doesn't work.

@bot.tree.command(name="disconnect", description="Disconnect from a vc",guild=guild)
async def disconnect(ctx: commands.Context):
    if not ctx.client:
        return await ctx.send("I am not in vc")
    elif not ctx.user.voice:
        return await ctx.send("You are not in vc")
    else:
        vc: wavelink.Player = ctx.client
    
    await vc.disconnect()
    vc.queue.clear()
    await ctx.send("Bye-bye")
2 Answers

The bot.tree.command decorator's first parameter in the function given isn't commands.Context, it's discord.Interaction as your error is telling you

I found the answer create guild = Interaction.guild and then user this guild.voice_client

Related