From 617eaa047d53190057296cbcfea04fc0a7faf2d8 Mon Sep 17 00:00:00 2001 From: iiLarsH Date: Tue, 25 Apr 2023 20:35:44 +0200 Subject: [PATCH] Basic functionality !roll !ping Hiding token --- .gitignore | 3 +++ bot.py | 23 +++++++++++++++++++++++ cogs/ping.py | 19 +++++++++++++++++++ cogs/roll.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 bot.py create mode 100644 cogs/ping.py create mode 100644 cogs/roll.py diff --git a/.gitignore b/.gitignore index 68bc17f..286b286 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +# token +/discordtoken \ No newline at end of file diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..df0b086 --- /dev/null +++ b/bot.py @@ -0,0 +1,23 @@ +from discord.ext import commands +import discord +import os +import asyncio +from discordtoken import discordtoken + +client = commands.Bot(command_prefix="!", intents=discord.Intents.all()) + +@client.event +async def on_ready(): + print("Succes: Bot has started working") + +async def load(): + for filename in os.listdir("./cogs"): + if filename.endswith(".py"): + await client.load_extension(f"cogs.{filename[:-3]}") + +async def main(): + async with client: + await load() + await client.start(discordtoken.get()) + +asyncio.run(main()) \ No newline at end of file diff --git a/cogs/ping.py b/cogs/ping.py new file mode 100644 index 0000000..8da862b --- /dev/null +++ b/cogs/ping.py @@ -0,0 +1,19 @@ +import discord +from discord.ext import commands + +class Ping(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.Cog.listener() + async def on_ready(self): + print("Ping.py is ready") + + @commands.command() + async def ping(self, ctx): + bot_latency = round(self.client.latency * 1000) + await ctx.send(f"pong! {bot_latency}ms.") + + +async def setup(client): + await client.add_cog(Ping(client)) \ No newline at end of file diff --git a/cogs/roll.py b/cogs/roll.py new file mode 100644 index 0000000..9d4953b --- /dev/null +++ b/cogs/roll.py @@ -0,0 +1,43 @@ +import discord +from discord.ext import commands +import random + +class Roll(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.Cog.listener() + async def on_ready(self): + print("roll.py is ready") + + @commands.command() + async def roll(self, ctx): + rolled = random.randint(1,100) + rating = "" + + if(rolled == 100): + rating = "What a chad" + elif(rolled < 100 and rolled > 90): + rating = "Almost" + elif(rolled <= 90 and rolled > 80): + rating = "Good" + elif(rolled <= 80 and rolled > 69): + rating = "Alright" + elif(rolled == 69): + rating = "Nice" + elif(rolled < 69 and rolled > 50): + rating = "Decent" + elif(rolled <= 50 and rolled > 25): + rating = "Meh" + elif(rolled <= 25 and rolled > 1): + rating = "Almost" + elif(rolled == 1): + rating = "LOL" + + message = "You rolled " + str(rolled) + ", " + rating + + await ctx.send(message) + + +async def setup(client): + await client.add_cog(Roll(client)) \ No newline at end of file