Package Logging¶
This package features a fairly decent set of built-in logging, the recommend logging level is logging.WARNING or logging.INFO
Basic Usage¶
Add this into your main.py/bot.py file, be aware this will also setup logging for discord.py and any other modules which use it.
1logging.basicConfig(
2 format="%(levelname)-7s | %(asctime)s | %(filename)12s:%(funcName)-12s | %(message)s",
3 datefmt="%I:%M:%S %p %d/%m/%Y",
4 level=logging.INFO,
5)
A more full example,
1import logging
2
3import discord
4from discord.ext import commands
5
6from antispam import AntiSpamHandler
7from jsonLoader import read_json
8
9logging.basicConfig(
10 format="%(levelname)s | %(asctime)s | %(module)s | %(message)s",
11 datefmt="%d/%m/%Y %I:%M:%S %p",
12 level=logging.INFO,
13)
14
15bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
16
17file = read_json("token")
18
19# Generally you only need/want AntiSpamHandler(bot)
20bot.handler = AntiSpamHandler(bot, ignore_bots=False)
21
22
23@bot.event
24async def on_ready():
25 # On ready, print some details to standard out
26 print(f"-----\nLogged in as: {bot.user.name} : {bot.user.id}\n-----")
27
28
29@bot.event
30async def on_message(message):
31 await bot.handler.propagate(message)
32 await bot.process_commands(message)
33
34
35if __name__ == "__main__":
36 bot.run(file["token"])