So, I am making a discord music bot and when the person searches something it plays the music, and it uses the valuable arg for that so for example: ?play christmas song but altough it does play the music correctly it sends this message: Now playing: ('christmas', 'song') It's like it cuts the 2 words and puts them both in like a sort of list?
This is my code:
@commands.command()
async def play(self, ctx, *arg):
if ctx.author.voice is None:
await ctx.send("Join a voice channel")
voice_channel = ctx.author.voice.channel
if ctx.voice_client is None:
await voice_channel.connect()
else:
await ctx.voice_client.move_to(voice_channel)
ctx.voice_client.stop()
try:
requests.get("" str(arg))
except: arg = " " str(arg)
else: arg = "" str(arg)
YDL_OPTIONS = {'format':"bestaudio"}
vc = ctx.voice_client
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(f"ytsearch:{arg}", download=False)
if 'entries' in info:
video = info['entries'][0]
else:
video = info
url2 = video['formats'][0]['url']
print(video)
video_url = video['url']
print(video_url)
source = await discord.FFmpegOpusAudio.from_probe(url2, **FFMPEG_OPTIONS)
await ctx.send("Now playing: **" str(arg) "**")
vc.play(source)
CodePudding user response:
Instead of doing async def play(self, ctx, *arg):
do async def play(self, ctx, *, arg):
by making a keyword argument, it tells discord.py to consume all of the arguments passed to that single argument
so a command invoked as {prefix}play hello from adelle
, in your command, your arg
will be hello from adelle
CodePudding user response:
It's because you're just print what you receive as parameter, you need to decouple the arg as like this:
await ctx.send("Now playing: **" *arg "**")
or
await ctx.send("Now playing: **" ' '.join(arg) "**")