Reputation: 13
My music bot built with hikari is unable to join. I have copied the code that I had used from discord.py. It worked properly on discord.py but wont work on hikari for some reason.
Here's the code:
@bot.command
@lightbulb.command('join', 'Makes bot join a voice channel')
@lightbulb.implements(lightbulb.PrefixCommand)
async def join(ctx):
try:
channel = ctx.message.author.voice.channel
await channel.connect()
await ctx.respond("I\'m in")
except:
await ctx.respond("You need to be connected to a voice channel in order for me to join")
@bot.command
@lightbulb.command('play', 'Plays track in connected voice channel')
@lightbulb.implements(lightbulb.PrefixCommand)
async def play(ctx, q: str):
YDL_OPTIONS = {'default_search': 'auto', 'format': 'bestaudio', 'noplaylist':'True'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
voice = ctx.message.guild.voice_client
with YoutubeDL(YDL_OPTIONS) as ydl:
try:
info = ydl.extract_info(q, download=False)
a = info['entries'][0]['formats'][0]['url']
queue.append(a)
if voice.is_playing():
await ctx.respond('I have queued the track')
else:
idk = queue[0]
queue.pop(0)
voice.play(FFmpegPCMAudio(idk, **FFMPEG_OPTIONS))
except:
info = ydl.extract_info(q, download=False)
a = info['url']
queue.append(a)
if voice.is_playing():
await ctx.respond('I have queued the track')
elif len(queue)==0:
idk = queue[0]
voice.play(FFmpegPCMAudio(idk, **FFMPEG_OPTIONS))
else:
idk = queue[0]
queue.pop(0)
voice.play(FFmpegPCMAudio(idk, **FFMPEG_OPTIONS))
Upvotes: 0
Views: 1279
Reputation: 136
Your command implementation is not the way that Lightbulb handles commands. Command arguments are not passed as arguments to the callback function, they are accessed via ctx.options.your_option_here
.
Reference: The option decorator
Example command that accepts an argument:
@bot.command
@lightbulb.option("q", "The track to play.")
@lightbulb.command("play", "Plays track in connected voice channel.")
@lightbulb.implements(lightbulb.PrefixCommand)
async def play(ctx: lightbulb.Context) -> None:
await ctx.respond(f"The song you want to play is {ctx.options.q}!")
Many of the attributes/methods you are using like ctx.message.guild.voice_client
, ctx.message.author.voice.channel
, and await channel.connect()
just do not exist in Hikari.
You can't transfer your discord.py code over 1:1.Hikari does implement the discord voice API, however you will need to read the documentation.
Connecting to a voice channel:
await bot.update_voice_state(ctx.guild_id, channel_id)
Disconnecting from a voice channel:
await bot.update_voice_state(ctx.guild_id, None)
Upvotes: 1