-
-
Save kar731/21d0a8d076e31d5f9125 to your computer and use it in GitHub Desktop.
This file contains 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
#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