fixed dynamic command listing for gifs
This commit is contained in:
1 parent
6eb850b7b3
commit
90793e33fe
1 file changed
+7
-5
+7
-5
@@ -6,6 +6,7 @@ from discord.ext import commands
|
||||
class Gifs(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self._gif_names = []
|
||||
self._load_gif_commands()
|
||||
|
||||
def _load_gif_commands(self):
|
||||
@@ -13,20 +14,21 @@ class Gifs(commands.Cog):
|
||||
return
|
||||
for filename in os.listdir('gifs'):
|
||||
if filename.endswith('.gif'):
|
||||
name = filename[:-4] # strip .gif
|
||||
name = filename[:-4]
|
||||
self._gif_names.append(name)
|
||||
self._make_command(name)
|
||||
|
||||
def _make_command(self, name: str):
|
||||
async def gif_command(self, ctx):
|
||||
async def gif_command(ctx):
|
||||
await ctx.reply(file=discord.File(f'gifs/{name}.gif'))
|
||||
gif_command.__name__ = name
|
||||
cmd = commands.command(name=name)(gif_command)
|
||||
self.add_command(cmd)
|
||||
self.bot.add_command(cmd)
|
||||
|
||||
@commands.command()
|
||||
async def gifs(self, ctx):
|
||||
gif_commands = [f'!{cmd.name}' for cmd in self.get_commands() if cmd.name != 'gifs']
|
||||
await ctx.reply('\n'.join(sorted(gif_commands)))
|
||||
gif_commands = [f'!{name}' for name in sorted(self._gif_names)]
|
||||
await ctx.reply('\n'.join(gif_commands))
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Gifs(bot))
|
||||
Reference in new issue
Block a user