-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_bot.py
69 lines (53 loc) · 1.76 KB
/
basic_bot.py
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
64
65
66
67
68
69
# basic_bot.py
import json, requests, html
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=";")
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"Basic bot code"))
# Importation du module
try:
bot.load_extension("EDT")
except Exception as e:
print('{}: {}'.format(type(e).__name__, e))
print(f'Logged in as {bot.user.name} on {len(bot.guilds)} servers')
#### Load - Unload - Reload an extension
@bot.command(name='reload')
@commands.is_owner()
async def reload(ctx, module : str):
"""Reloads a module."""
try:
bot.unload_extension(module)
bot.load_extension(module)
except Exception as e:
await ctx.send('{}: {}'.format(type(e).__name__, e))
else:
await ctx.send('`Module {} has been successfully reloaded.`'.format(module))
@bot.command(name='load')
@commands.is_owner()
async def load(ctx, module : str):
"""Loads a module."""
try:
bot.load_extension(module)
except Exception as e:
await ctx.send('{}: {}'.format(type(e).__name__, e))
else:
await ctx.send('`Module {} has been loaded.`'.format(module))
@bot.command(name='unload')
@commands.is_owner()
async def unload(ctx, module : str):
"""Unloads a module."""
try:
bot.unload_extension(module)
except Exception as e:
await ctx.send('{}: {}'.format(type(e).__name__, e))
else:
await ctx.send('`Module {} has been unloaded.`'.format(module))
###### ON ERROR ######
@bot.event
async def on_command_error(ctx, error):
print(f"ERR - {ctx.command} - {error}")
with open("AdabGuardian/tok.json", 'r') as readFile:
TOKEN = json.load(readFile)
bot.run(TOKEN)