Skip to content

Commit

Permalink
Added bot and several commands
Browse files Browse the repository at this point in the history
  • Loading branch information
slushiegoose committed Jul 19, 2021
1 parent 4a84ca0 commit 8f98ebf
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Suhail/cogs/clear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import discord
from discord.ext import commands

class Clear(commands.Cog):

def __init__(self, bot): self.bot = bot

@commands.command()
async def clear(self, ctx, num: int):
try:
await ctx.channel.purge(limit=num)
except discord.Forbidden:
await ctx.send("Oops i can't do that rip")

def setup(bot):
bot.add_cog(Clear(bot))
15 changes: 15 additions & 0 deletions Suhail/cogs/error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import discord
from discord.ext import commands

class Error(commands.Cog):

def __init__(self, bot):
self.bot = bot

@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send("I only accept numbers smh")

def setup(bot):
bot.add_cog(Error(bot))
31 changes: 31 additions & 0 deletions Suhail/cogs/hi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import discord
from discord.ext import commands

class Hi(commands.Cog):

def __init__(self, bot: commands.Bot):
self.bot = bot

@commands.command()
async def ping(self, ctx):
return await ctx.send(f"Pong! :ping_pong: Latency: {round(self.bot.latency*1000, 2)}ms")

@commands.command()
async def hi(self, ctx, name = None):
name = name or ctx.author.display_name
await ctx.send(f"hello {name}!")

@commands.command()
async def greet(self, ctx):
await ctx.author.send("Private Greeting oooooooooo")

@commands.command()
async def sort(self, ctx, *args):
await ctx.send("\n".join(sorted(args)))

@commands.command()
async def logo(self, ctx):
await ctx.send(file=discord.File("logo.png"))

def setup(bot):
bot.add_cog(Hi(bot))
25 changes: 25 additions & 0 deletions Suhail/cogs/random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import discord
import random
from discord.ext import commands

class Random(commands.Cog):

def __init__(self, bot):
self.bot = bot

@commands.command()
async def flip(self, ctx, count: int):
if count < 0: return await ctx.send("Can't flip a negative number of coins")
if count == 0: return await ctx.send("Well... you flipped nothing so... Nothing")
await ctx.send(" ".join(random.choice(["H", "T"]) for x in range(count)))

@commands.command()
async def roll(self, ctx, count: int):
print("HERE")
if count < 0: return await ctx.send("Can't roll a negative number of dice")
if count == 0: return await ctx.send("Well... you rolled nothing so... Nothing")

await ctx.send(" ".join(str(random.randint(1, 6)) for x in range(count)))

def setup(bot):
bot.add_cog(Random(bot))
1 change: 1 addition & 0 deletions Suhail/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TOKEN = "ODY2NjQxODMxODg2NzE2OTI4.YPVhGg.gs4sKIc1yEPsSaCGaBE93OU6ENc"
15 changes: 15 additions & 0 deletions Suhail/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import config
import discord
from discord.ext import commands

class Bot(commands.Bot):
async def on_ready(self):
print(f"READY! Loaded {self.user}")
self.load_extension("cogs.hi")
self.load_extension("cogs.clear")
self.load_extension("cogs.error")
self.load_extension("cogs.random")

bot = Bot(command_prefix="!")

bot.run(config.TOKEN)

0 comments on commit 8f98ebf

Please sign in to comment.