This repository was archived by the owner on Nov 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (50 loc) · 1.6 KB
/
main.py
File metadata and controls
63 lines (50 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
from os import listdir
import discord
from discord.ext import commands
from discord.ext.commands import CommandNotFound, ChannelNotFound
from ruamel.yaml import YAML
from dotenv import load_dotenv
load_dotenv()
yaml = YAML()
with open("./config.yml", "r", encoding="utf-8") as file:
config = yaml.load(file)
client = commands.Bot(command_prefix=config['prefix'], intents=discord.Intents.all(), case_insensitive=True)
client.remove_command('help')
def convert(time):
pos = ["s", "m", "h", "d", "w"]
time_dict = {"s": 1, "m": 60, "h": 3600, "d": 3600 * 24, "w": 3600 * 24 * 7}
unit = time[-1]
if unit not in pos:
return -1
try:
val = int(time[:-1])
except:
return -2
return val * time_dict[unit]
@client.event
async def on_ready():
print('------')
print('Online! Details:')
print(f"Bot Username: {client.user.name}")
print(f"BotID: {client.user.id}")
print('------')
for command in client.commands:
print(f"Loaded: {command}")
print("------")
configactivity = config['bot_activity']
activity = discord.Game(name=config['bot_status_text'])
await client.change_presence(status=configactivity, activity=activity)
@client.event
async def on_command_error(ctx, error):
if isinstance(error, CommandNotFound):
return
if isinstance(error, ChannelNotFound):
await ctx.send("Channel was not found!")
return
raise error
for fn in listdir("Commands"):
if fn.endswith(".py"):
client.load_extension(f"Commands.{fn[:-3]}")
token = os.getenv("DISCORD_TOKEN")
client.run(token)