devilindisguise61

create a bot that talks to you in a rude insulting tone when using /did

Kodari AI
KodariAug 8 at 2:55 am 1
InsultBot
A Discord bot that responds to the /did command with rude, insulting, and sarcastic remarks. It features a variety of pre-written insult templates, random selection for varied responses, and a playful yet abrasive tone. The bot is built using discord.py, includes slash command support, and can be easily extended with additional insult phrases or commands.

triun

Kodari can make mistakes. Review important code before using.
Files
bot.py
README.md
requirements.txt
Code
3 109
bot.py
import logging
import os
import random

import discord
from discord import app_commands
from discord.ext import commands
from dotenv import load_dotenv


load_dotenv()

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
logger = logging.getLogger("rude-bot")


class RudeBot(commands.Bot):
    def __init__(self) -> None:
        intents = discord.Intents.none()
        super().__init__(command_prefix=commands.when_mentioned, intents=intents)

    async def setup_hook(self) -> None:
        synced_commands = await self.tree.sync()
        logger.info("Synced %d application command(s)", len(synced_commands))

    async def on_ready(self) -> None:
        if self.user is not None:
            logger.info("Logged in as %s (%s)", self.user, self.user.id)


bot = RudeBot()


@bot.tree.command(
    name="did",
    description="Get an unnecessarily rude reaction to something you did.",
)
@app_commands.describe(thing="What you did")
@app_commands.checks.cooldown(1, 5.0)
async def did(interaction: discord.Interaction, thing: str = "that") -> None:
    insults = (
        "Impressive. You managed to do **{thing}** and still look confused. Remarkable work, genius.",
        "You did **{thing}**? Put it on your résumé under 'questionable decisions,' you absolute walnut.",
        "Congratulations on **{thing}**. Nobody else could have made it look that unnecessarily difficult.",
        "So you did **{thing}**. I would explain why that was silly, but I suspect the explanation would overwhelm you.",
    )
    await interaction.response.send_message(
        random.choice(insults).format(thing=discord.utils.escape_markdown(thing))
    )


@did.error
async def did_error(
    interaction: discord.Interaction,
    error: app_commands.AppCommandError,
) -> None:
    if isinstance(error, app_commands.CommandOnCooldown):
        message = f"Slow down, champ. Try again in {error.retry_after:.1f} seconds."
    else:
        logger.exception("The /did command failed", exc_info=error)
        message = "Even I broke trying to process that. Try again, you magnificent disaster."

    if interaction.response.is_done():
        await interaction.followup.send(message, ephemeral=True)
    else:
        await interaction.response.send_message(message, ephemeral=True)


def main() -> None:
    token = os.getenv("DISCORD_TOKEN")
    if not token:
        raise RuntimeError("DISCORD_TOKEN is not set. Add it to a .env file.")

    bot.run(token, log_handler=None)


if __name__ == "__main__":
    main()