Last active
November 2, 2020 17:42
-
-
Save 15696/20e67b5af9912577b30eb447516de499 to your computer and use it in GitHub Desktop.
simple subreddit converter example in discord.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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