-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
executable file
·68 lines (49 loc) · 1.68 KB
/
bot.py
File metadata and controls
executable file
·68 lines (49 loc) · 1.68 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
64
65
66
67
68
#!/usr/bin/env python3
import argparse
import asyncio
import logging
import os
import sys
from typing import Optional
import discord
import dotenv
from discord.ext import commands
dotenv.load_dotenv()
logging.basicConfig(
format="%(asctime)s [%(levelname)s]: %(message)s", level=logging.INFO
)
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
@bot.event
async def on_ready():
logging.info(f"successfully logged in as {bot.user}")
@bot.event
async def on_message(msg: discord.Message):
await bot.process_commands(msg)
@bot.event
async def on_command_error(ctx: commands.Context, error: commands.errors.CommandError):
if isinstance(error, (commands.CommandOnCooldown, commands.UserInputError)):
await ctx.send(str(error))
initial_exts = ["cogs.demo"]
async def main():
parser = argparse.ArgumentParser()
parser.add_argument("--token", help="specify a Discord bot token")
parser.add_argument("--debug", help="set the debug loglevel", action="store_true")
parser.add_argument(
"--quiet", help="silence everything except errors", action="store_true"
)
args = parser.parse_args()
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)
elif args.quiet:
logging.getLogger().setLevel(logging.ERROR)
token: Optional[str] = args.token or os.getenv("DISCORD_TOKEN")
if not token:
logging.error("no token specified, use --token or set DISCORD_TOKEN")
sys.exit(1)
async with bot:
for ext in initial_exts:
await bot.load_extension(ext)
await bot.start(token)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())