Skip to content

Instantly share code, notes, and snippets.

@15696
Last active November 2, 2020 17:42
Show Gist options
  • Save 15696/20e67b5af9912577b30eb447516de499 to your computer and use it in GitHub Desktop.
Save 15696/20e67b5af9912577b30eb447516de499 to your computer and use it in GitHub Desktop.
simple subreddit converter example in discord.py
class Subreddit(commands.Converter):
async def convert(self, arg):
if arg.startswith("r/"):
arg = arg[2:]
return arg
@client.command()
async def convert(ctx, subreddit: Subreddit): # use a typehint to specify converter
await ctx.send(subreddit)
# if we invoke the convert command with "r/testsubreddit"
# it will send back "testsubreddit" and if we invoke it with
# "testsubreddit" the output will stay the same as the input.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment