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
Nzg0OTk3MTkyMzM0ODM1NzEy.X8xbmw.eGM6T5AAQVPpqdOW-EzEU0h6ayI |
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
# thanks to mental32 on github for the idea | |
# thanks to sleep-cult#3040 on discord for the help | |
token = "put your token here" | |
(lambda c, a: [ | |
f(c, a) for f in [ | |
lambda c, a: [c.__setattr__(k, a.coroutine(v)) for k, v in { | |
"on_ready": lambda: print("Ready!"), |
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
NzgyMzA1MTE4ODg4MDAxNTQ2.X8KQag.y4_7W7ffUC3m2pBj3JeOEdgM4t4 |
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
# main.py | |
from discord.ext import commands | |
import os | |
client = commands.Bot(command_prefix = "!") | |
for f in os.listdir("./cogs"): | |
if f.endswith(".py"): | |
client.load_extension("cogs." + f[:-3]) |
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 Member(commands.Converter): | |
async def convert(self, arg): | |
if arg == "": | |
return ctx.author | |
return discord.Member.convert(arg) |
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
{"Version": "1.1", "URL": "https://www.icloud.com/shortcuts/2ed58291f7f84f3da7990379d8516164", "Notes": "Added stuff."} |
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
bot_msg = await ctx.send("what is 2 + 3?") | |
def check(message): | |
return message.channel == bot_msg.channel | |
try: | |
msg = bot.wait_for("message", check = check, timeout = 60) # timeout is 60 by default | |
except asyncio.exceptions.TimeoutError: | |
# user didnt reply in 60 seconds | |
else: |
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
@client.event | |
async def on_command_error(ctx, error): | |
if isinstance(error, commands.CommandOnCooldown): | |
await ctx.send(f"{round(error.retry_after, 2)} seconds left") | |
@client.command() | |
@commands.cooldown(1, 5, commands.BucketType.user) | |
async def command(ctx): | |
await ctx.send("command output") |
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) |
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
# bot.py | |
from .context import CustomContext | |
class Bot(commands.Bot): | |
"""A subclass of commands.Bot, useful for creating custom context.""" | |
async def get_context(self, message, *, cls = CustomContext): | |
return await super().get_context(message, cls = cls) | |
# context.py | |
class CustomContext(commands.Context): |
NewerOlder