I have a debug command for my bot that prints all of the current stacks that are running. Problem is it also prints my bot token. Rather than making it so it doesnt print my token, i'd rather make it so the debug command can only be ran by me.
my program:
`import discord from discord.ext import commands from discord.ext.commands.core import command import youtube_dl import traceback from tabulate import tabulate
table = [['Song', 'Queued by', 'Duration']]
class music(commands.Cog): def init(self, client): self.client = client
@commands.command()
async def join(self, ctx):
await ctx.send("Hello!", ctx.author)
if ctx.author.voice is None:
await ctx.send("Join a voice channel please.")
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)
@commands.command()
async def disconnect(self, ctx):
await ctx.voice_client.disconnect()
@commands.command()
async def play(self, ctx, url):
ctx.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
YDL_OPTIONS = {'format':"bestaudio"}
vc = ctx.voice_client
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
source = await discord.FFmpegOpusAudio.from_probe(url2, **FFMPEG_OPTIONS)
vc.play(source)
@commands.command()
async def pause(self, ctx):
await ctx.voice_client.pause()
await ctx.send("Music is paused.")
@commands.command()
async def online(self, ctx):
await ctx.send("The bot is online.")
@commands.command()
async def debug(self,ctx):
await ctx.send("You are: ")
await ctx.send(ctx.author)
await ctx.send("You are in the channel:")
if ctx.author.voice:
await ctx.send(ctx.author.voice.channel)
else:
await ctx.send("None")
await ctx.send("Stack: ")
for line in traceback.format_stack():
await ctx.send(line.strip())
@commands.command()
async def resume(self, ctx):
await ctx.voice_client.resume()
await ctx.send("Music has been resumed.")
@commands.command()
async def queue(self, ctx):
await ctx.send(tabulate(table, headers='firstrow'))
def setup(client): client.add_cog(music(client))`
CodePudding user response:
You can for example return
when the user's id that used the command is not yours:
@commands.command()
async def debug(self, ctx):
if ctx.author.id != "your id":
return
# The rest of your debug command