Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.72k stars 3.75k forks source link

ctx.voice_client always return None #9026

Closed Karnatour closed 1 year ago

Karnatour commented 1 year ago

Summary

ctx.voice_client always return None even bot is connected to channel

Reproduction Steps

first execute join command after that execute channel command. I tried using ctx.guild.voice_client i got same result. I tried contacting help forum in discord https://discord.com/channels/336642139381301249/1034774703262421033 and also tried to get help in help channel

Minimal Reproducible Code

@bot.command(help="Připoj se do kanálu")
async def join(ctx: commands.Context):
    if ctx.author.voice and ctx.author.voice.channel:
        await ctx.guild.change_voice_state(channel=ctx.author.voice.channel)
        await lavalink.wait_for_connection(ctx.guild.id)
    else:
        await ctx.send("Musíš být v kanále pro použití tohoto commandu")

@bot.command(help="channel")
async def channel(ctx: commands.Context):
    if ctx.voice_client is None:
        return await ctx.send("Bot is not in channel")
    else:
        await ctx.send(ctx.voice_client)

Expected Results

Bot should send message in which channel he currently is

Actual Results

ctx.voice_client returned None

Intents

intents = discord.Intents.all()

System Information

Checklist

Additional Context

Full code can be found here: https://github.com/Karnatour/Votabot/blob/main/main.py

Rapptz commented 1 year ago

This library does not use VoiceProtocol or VoiceChannel.connect. This is seemingly because it wants to abstract whatever Discord library it's using for forks or other implementations. Since it's bypassing this machinery it doesn't get populated by Context.voice_client or Guild.voice_client.

If you want this to work you'll need to find another library to do this with, the lavalink repository has many other lavalink wrappers. Notably, these would not require the use of debug events or finicky code to function like the library you're using.

In the future, please restrict questions to the discord server instead of the issue tracker.

Thanks.