Skip to content

Instantly share code, notes, and snippets.

@kar731
Created March 5, 2016 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kar731/21d0a8d076e31d5f9125 to your computer and use it in GitHub Desktop.
Save kar731/21d0a8d076e31d5f9125 to your computer and use it in GitHub Desktop.
#imports discord and the cog library
import discord
from discord.ext import commands
#this is the cog / extension
class Template:
#needed to make the bot work
def __init__(self, bot):
self.bot = bot
#this is how you register a command.
#hidden = True means that when you do [command bang]help it won't show
@commands.command(hidden=True)
#function of the command
async def template_print(self):
#the bot will say "sup" in the chat
await self.bot.say("sup")
#pass_context will pass on the message info of the person who called the command
@commands.command(pass_context=True)
#ctx is needed for the pass_context
#num is a sub-command thing like !clearbot 29
async def clearbot(self, ctx, num: int):
"""Deletes recent messages"""
count = 0
if num < 0:
return
while count <= num:
del_flag = False
async for msg in self.bot.logs_from(ctx.message.channel, limit=100):
if count == num:
break
elif msg.author.id == self.bot.user.id:
count += 1
del_flag = True
await self.bot.delete_message(msg)
if not del_flag:
break
#for the bot to add the cog. replace template with the classname
def setup(bot):
bot.add_cog(Template(bot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment