R
R
reverend-dikiy2021-07-06 13:36:23
Python
reverend-dikiy, 2021-07-06 13:36:23

How to connect a bot by voice channel ID?

Good day.
There is a code:

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


How instead ctx.author.voice.channel, to register the ID of the voice channel

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2021-07-10
@revrend-dikiy

@bot.command()
async def join(ctx, *, voice: discord.VoiceChannel):
    # https://discordpy.readthedocs.io/en/stable/ext/commands/commands.html#converters
    # https://discordpy.readthedocs.io/en/stable/ext/commands/commands.html#keyword-only-arguments
    await voice.connect()

If you need a specific preset channel:
@bot.command()
async def join(ctx):
    await bot.get_channel(117454459249562234).connect()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question