Files
bot.py
requirements.txt
Code
2 57
bot.py
import logging
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("kukkel_bot")
load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=".", intents=intents)
@bot.event
async def on_ready():
logger.info("Logged in as %s", bot.user)
print("KODARI_READY", flush=True)
@bot.command(name="kukkel")
@commands.guild_only()
@commands.has_guild_permissions(administrator=True)
@commands.cooldown(1, 60, commands.BucketType.guild)
async def kukkel(ctx: commands.Context):
channel = discord.utils.get(ctx.guild.text_channels, name="vene-pomm")
if channel is None:
await ctx.reply("I couldn't find a text channel named `vene-pomm`.", mention_author=False)
return
await channel.send("Admin notice: the `.kukkel` command was used. No members were banned or otherwise modified.")
@kukkel.error
async def kukkel_error(ctx: commands.Context, error: commands.CommandError):
if isinstance(error, commands.MissingPermissions):
await ctx.reply("Only a server administrator can use this command.", mention_author=False)
elif isinstance(error, commands.CommandOnCooldown):
await ctx.reply(f"Please wait {error.retry_after:.0f} seconds before using this again.", mention_author=False)
elif isinstance(error, commands.NoPrivateMessage):
await ctx.reply("This command can only be used in a server.", mention_author=False)
else:
logger.exception("Command failed", exc_info=error)
await ctx.reply("The command failed. Check the bot logs for details.", mention_author=False)
token = os.getenv("DISCORD_TOKEN")
if not token or token == "your_discord_bot_token_here":
raise RuntimeError("Set DISCORD_TOKEN in the .env file before starting the bot.")
bot.run(token)