Created
September 16, 2020 13:51
-
-
Save Arthurdw/85b704b045ff87007994a2e620fcdc09 to your computer and use it in GitHub Desktop.
Adding a event listener
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
from typing import Optional | |
from discord import Member | |
from discord.ext.commands import command, Bot, Context | |
from utilsx.discord import BotX, Cog | |
BOT_TOKEN = "XXXYOURBOTTOKENHEREXXX" | |
class MyBot(BotX): | |
def __init__(self): | |
super().__init__() | |
self.add_cog(CustomCommands(self)) | |
class CustomCommands(Cog): | |
def __init__(self, bot: Bot): | |
super().__init__() | |
self.bot = bot | |
@command() | |
async def hello(self, ctx: Context): | |
await self.send(ctx, f"Hello {ctx.author.mention}") | |
@command() | |
async def kick(self, ctx: Context, target: Member, reason: Optional[str]): | |
await self.embed(target, f"You have been banned from {ctx.guild.name}{(' for ' + reason) if reason else '' }") | |
await target.kick(reason=reason) | |
await self.embed(ctx, f"Successfully kicked {target}") | |
@Cog.listener() | |
async def on_ready(self): | |
print(f"{self.bot.user} is ready!") | |
if __name__ == "__main__": | |
MyBot().run(BOT_TOKEN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment