Skip to content

Instantly share code, notes, and snippets.

@Kakarot-2000
Created February 26, 2021 10:05
Show Gist options
  • Save Kakarot-2000/1e01a5258bcdf3dadf7360e992540338 to your computer and use it in GitHub Desktop.
Save Kakarot-2000/1e01a5258bcdf3dadf7360e992540338 to your computer and use it in GitHub Desktop.
@bot.command(name='play_song', help='To play song')
async def play(ctx,url):
if not ctx.message.author.name=="Rohan Krishna" :
await ctx.send('NOT AUTHORISED!')
return
try :
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
filename = await YTDLSource.from_url(url, loop=bot.loop)
voice_channel.play(discord.FFmpegPCMAudio(executable="ffmpeg.exe", source=filename))
await ctx.send('**Now playing:** {}'.format(filename))
except:
await ctx.send("The bot is not connected to a voice channel.")
@bot.command(name='pause', help='This command pauses the song')
async def pause(ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_playing():
await voice_client.pause()
else:
await ctx.send("The bot is not playing anything at the moment.")
@bot.command(name='resume', help='Resumes the song')
async def resume(ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_paused():
await voice_client.resume()
else:
await ctx.send("The bot was not playing anything before this. Use play_song command")
@bot.command(name='stop', help='Stops the song')
async def stop(ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_playing():
await voice_client.stop()
else:
await ctx.send("The bot is not playing anything at the moment.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment