feat: log
This commit is contained in:
parent
cdd68052ca
commit
cf22845aa6
1 changed files with 10 additions and 2 deletions
12
main.py
12
main.py
|
@ -1,9 +1,12 @@
|
|||
from configparser import ConfigParser
|
||||
import logging
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from configparser import ConfigParser
|
||||
|
||||
TOKEN = 'MTE1NDc0ODQ3MzE4MzMwNTc4OQ.Gz_Q7u.02sb2YNV_QQy7Bs19roXlB62mjoMKA6y8aubHU' # Bot token (replace with your own)
|
||||
DEFAULT_CONFIG_FILE = 'config.ini' # Configuration file with server IDs and study group roles
|
||||
DEFAULT_LOG_FILE = 'kruhobot.log' # Log file for the bot
|
||||
|
||||
|
||||
# Create an instance of the bot
|
||||
|
@ -12,6 +15,9 @@ intents.members = True
|
|||
|
||||
bot = commands.Bot(command_prefix='!', intents=intents)
|
||||
|
||||
logging.basicConfig(filename=DEFAULT_LOG_FILE, level=logging.INFO)
|
||||
logger = logging.getLogger("Kruhobot")
|
||||
|
||||
|
||||
async def reply_error(ctx: commands.Context, message: str):
|
||||
await reply(ctx, f'**Error:** {message}', True)
|
||||
|
@ -49,7 +55,7 @@ def init(config):
|
|||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f'Logged in as {bot.user.name}')
|
||||
logger.info(f'Logged in as {bot.user.name}')
|
||||
|
||||
|
||||
@bot.command()
|
||||
|
@ -74,9 +80,11 @@ async def grant_role(ctx, study_group_name: str):
|
|||
if role is not None:
|
||||
await author.add_roles(role)
|
||||
await reply(ctx, f'{author.mention} has been granted the {study_group_name} role on the [{guild.name}] server.')
|
||||
logger.info(f'Granted role [{role_name}] to [{author_id}] in [{guild_id}] corresponding to the study group [{study_group_name}].')
|
||||
return
|
||||
|
||||
await reply_error(ctx, 'Something went wrong. Please check your command and try again.')
|
||||
logger.error(f'Failed to grant a role to [{author_id}] in [{guild_id}] corresponding to the study group [{study_group_name}].')
|
||||
return
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue