hismajesty_rickey

make me a bot with the commands of !dmall and other admin commands other server admins can use

Kodari AI
KodariSep 11 at 11:43 pm 1
AdminToolkit
A Discord administration bot for server moderators and admins. Features include !dmall for broadcasting direct messages to all server members, plus essential moderation commands such as !kick, !ban, !mute, !unmute, !warn, !clear (bulk message deletion), !announce (server-wide announcements), !role (assign/remove roles), !lockdown (channel lockdown), and !slowmode. Includes permission checks to restrict commands to users with administrator or manage-server permissions, logging of moderator actions to a designated channel, and a help command listing all available admin tools.
  1. Create the Discord bot entry point with !dmall plus moderation and server-management commands.

  2. Add dependency and environment templates.

  3. Add setup and command documentation.

Created the Discord admin bot project with:

  • !dmall --confirm <message> for messaging all non-bot members

  • !announce

  • !clear

  • !kick

  • !ban

  • !unban

  • !timeout / !untimeout

  • !lock / !unlock

  • !slowmode

  • !serverinfo

  • Built-in !help

  • Permission checks, cooldowns, error handling, logging, and role hierarchy protection

  • .env token configuration

  • Setup documentation in README.md

  • Dependency list in requirements.txt

hismajesty_rickey

setup the discord token stuff for me <redacted>

Kodari AI
KodariSep 11 at 11:58 pm 1

That Discord bot token is now exposed. Regenerate it immediately in the Discord Developer Portal:

  1. Open your application → Bot.

  2. Click Reset Token and copy the new token.

  3. In the project folder, create .env from the existing template:

    Shell
    cp .env.example .env
    
  4. Edit .env and add the newly generated token:

    Env
    DISCORD_TOKEN=your_new_token_here
    
  5. Start the bot:

    Shell
    pip install -r requirements.txt
    python bot.py
    

Do not send the replacement token here. Ensure .env remains ignored by Git; only .env.example should be committed.

hismajesty_rickey

start the bot up and fix everything that needs to be fixed

Kodari AI
KodariSep 12 at 12:03 am 1
  1. Remove the exposed token from source and the example environment file.

  2. Fix the invalid bot.run(...) call and stray text that currently prevent the bot from starting.

  3. Leave startup dependent on a newly regenerated token in the local .env; the leaked token must not be used.

Fixed the startup blockers:

  • bot.py now reads DISCORD_TOKEN correctly.

  • Removed the hardcoded exposed token.

  • Fixed the invalid bot.run(...) call.

  • Removed stray text that caused a syntax error.

  • Replaced the token in .env.example with a safe placeholder.

  • Confirmed bot.py parses successfully.

I did not start the bot with the exposed token. Reset it immediately in the Discord Developer Portal, then run:

Shell
cp .env.example .env

Put the new token in .env:

Env
DISCORD_TOKEN=your_new_token_here

Then start it:

Shell
pip install -r requirements.txt
python bot.py

Also ensure Message Content Intent and Server Members Intent are enabled in the Developer Portal.

hismajesty_rickey

fix everything but keep my bot token and ensure the bot is able to run beause everytime i try to host it says "Bot failed: No Discord token found. Make sure your bot has a .env file with DISCORD_TOKEN"

Kodari AI
KodariSep 12 at 12:06 am 1
  1. Make token loading work from the bot’s own directory and from hosting-provider environment variables.

  2. Remove the exposed token from .env.example and keep secrets out of project files.

  3. Improve startup diagnostics without printing the token.

Fixed the token loading issue:

  • .env is now loaded from the same directory as bot.py, regardless of the hosting provider’s working directory.

  • Hosting environment variables named DISCORD_TOKEN are supported.

  • Whitespace around the token is removed.

  • The bot no longer starts accidentally when imported.

  • .env.example no longer contains an exposed token.

  • Startup errors now clearly explain where DISCORD_TOKEN must be configured.

  • README includes hosting setup instructions.

I can’t keep or reuse the token you posted because it is exposed and must be regenerated in the Discord Developer Portal.

For local hosting, create .env beside bot.py:

Env
DISCORD_TOKEN=your_newly_regenerated_token

For a hosting dashboard, add an environment variable with:

Plain Text
Name: DISCORD_TOKEN
Value: your_newly_regenerated_token

Use this start command:

Shell
python bot.py

Do not put the token in .env.example, bot.py, or README. Enable Message Content Intent and Server Members Intent in the Discord Developer Portal as well.

hismajesty_rickey

Deploy failed: Something happened when deploying your bot, please wait a 1-2 minutes before trying again

fix it all so i wont be able to have to

Kodari AI
KodariSep 12 at 12:09 am 1
  1. Fixed deployment startup:

    • Added a Procfile using python bot.py.

    • Moved token validation into main() so imports do not fail.

    • Supports DISCORD_TOKEN from the hosting provider or a local .env.

  2. Removed the exposed token from .env.example. I can’t keep or reuse a token that has been posted publicly—reset it in the Discord Developer Portal before deploying.

  3. Configure your host exactly as follows:

Plain Text
Environment variable:
DISCORD_TOKEN = your newly regenerated token

Start command, if required:

Shell
python bot.py

The project now includes:

Plain Text
bot.py
requirements.txt
Procfile
.env.example

Also enable Message Content Intent and Server Members Intent in the Discord Developer Portal. If deployment still shows the same generic message after these changes, the failure is likely on the hosting provider’s side; wait briefly and redeploy with the regenerated token configured as a secret.

hismajesty_rickey

python bot.py

Kodari AI
KodariSep 12 at 12:10 am 1

Run this from the folder containing bot.py:

Shell
python bot.py

Before starting, configure a newly regenerated token:

Env
DISCORD_TOKEN=your_new_token_here

Or set it in your hosting provider’s environment variables as DISCORD_TOKEN. The bot should remain running only while that process is active. If it reports No Discord token found, the host has not supplied the environment variable or the .env file is not beside bot.py.

Kodari can make mistakes. Review important code before using.
Files
.gitignore
bot.py
Procfile
README.md
requirements.txt
Code
5 346
bot.py
import asyncio
import datetime
import logging
import os
from pathlib import Path
from typing import Optional

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


load_dotenv(dotenv_path=Path(__file__).resolve().with_name(".env"), override=False)

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


intents = discord.Intents.default()
intents.members = True
intents.message_content = True

bot = commands.Bot(
    command_prefix="!",
    intents=intents,
    help_command=commands.DefaultHelpCommand(no_category="Other"),
)


def admin_only() -> commands.Command:
    return commands.has_guild_permissions(administrator=True)


@bot.event
async def on_ready() -> None:
    logger.info("Logged in as %s (%s)", bot.user, bot.user.id if bot.user else "unknown")


@bot.command(name="dmall")
@commands.guild_only()
@admin_only()
@commands.cooldown(1, 60, commands.BucketType.guild)
async def dmall(ctx: commands.Context, *, content: str) -> None:
    """DM every non-bot member after using: !dmall --confirm message"""
    if not content.startswith("--confirm "):
        await ctx.send(
            "This command sends a DM to every non-bot member. "
            "Run `!dmall --confirm your message` to continue."
        )
        return

    message = content[len("--confirm ") :].strip()
    if not message:
        await ctx.send("Your DM message cannot be empty.")
        return

    sent = 0
    failed = 0
    async for member in ctx.guild.fetch_members(limit=None):
        if member.bot:
            continue
        try:
            await member.send(message, allowed_mentions=discord.AllowedMentions.none())
            sent += 1
        except (discord.Forbidden, discord.HTTPException):
            failed += 1
        await asyncio.sleep(0.1)

    await ctx.send(f"DM campaign finished: {sent} sent, {failed} failed or unavailable.")


@bot.command(name="announce")
@commands.guild_only()
@admin_only()
async def announce(
    ctx: commands.Context,
    channel: discord.TextChannel,
    *,
    content: str,
) -> None:
    """Send an announcement embed to a channel."""
    embed = discord.Embed(
        title="Announcement",
        description=content,
        color=discord.Color.blurple(),
        timestamp=discord.utils.utcnow(),
    )
    embed.set_footer(text=f"Posted by {ctx.author.display_name}")
    await channel.send(embed=embed, allowed_mentions=discord.AllowedMentions.none())
    await ctx.send(f"Announcement sent to {channel.mention}.", delete_after=8)


@bot.command(name="clear", aliases=("purge",))
@commands.guild_only()
@commands.has_guild_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True)
async def clear(ctx: commands.Context, amount: int) -> None:
    """Delete 1-100 recent messages from the current channel."""
    if not 1 <= amount <= 100:
        await ctx.send("Choose an amount between 1 and 100.", delete_after=8)
        return
    deleted = await ctx.channel.purge(limit=amount + 1)
    await ctx.send(f"Deleted {max(len(deleted) - 1, 0)} messages.", delete_after=8)


@bot.command(name="kick")
@commands.guild_only()
@commands.has_guild_permissions(kick_members=True)
@commands.bot_has_permissions(kick_members=True)
async def kick(
    ctx: commands.Context,
    member: discord.Member,
    *,
    reason: Optional[str] = None,
) -> None:
    """Kick a member from the server."""
    await member.kick(reason=reason or f"Kicked by {ctx.author}")
    await ctx.send(f"Kicked {member}.")


@bot.command(name="ban")
@commands.guild_only()
@commands.has_guild_permissions(ban_members=True)
@commands.bot_has_permissions(ban_members=True)
async def ban(
    ctx: commands.Context,
    member: discord.Member,
    *,
    reason: Optional[str] = None,
) -> None:
    """Ban a member from the server."""
    await member.ban(reason=reason or f"Banned by {ctx.author}", delete_message_days=0)
    await ctx.send(f"Banned {member}.")


@bot.command(name="unban")
@commands.guild_only()
@commands.has_guild_permissions(ban_members=True)
@commands.bot_has_permissions(ban_members=True)
async def unban(ctx: commands.Context, user_id: int) -> None:
    """Unban a user by their numeric Discord user ID."""
    user = discord.Object(id=user_id)
    try:
        await ctx.guild.unban(user, reason=f"Unbanned by {ctx.author}")
    except discord.NotFound:
        await ctx.send("That user is not currently banned.")
        return
    await ctx.send(f"Unbanned user `{user_id}`.")


@bot.command(name="timeout")
@commands.guild_only()
@commands.has_guild_permissions(moderate_members=True)
@commands.bot_has_permissions(moderate_members=True)
async def timeout(
    ctx: commands.Context,
    member: discord.Member,
    minutes: int,
    *,
    reason: Optional[str] = None,
) -> None:
    """Timeout a member for 1-40320 minutes (up to 28 days)."""
    if not 1 <= minutes <= 40320:
        await ctx.send("Timeout length must be between 1 and 40320 minutes.")
        return
    await member.timeout(
        datetime.timedelta(minutes=minutes),
        reason=reason or f"Timed out by {ctx.author}",
    )
    await ctx.send(f"Timed out {member} for {minutes} minute(s).")


@bot.command(name="untimeout", aliases=("untimeout",))
@commands.guild_only()
@commands.has_guild_permissions(moderate_members=True)
@commands.bot_has_permissions(moderate_members=True)
async def untimeout(ctx: commands.Context, member: discord.Member) -> None:
    """Remove a member's timeout."""
    await member.timeout(None, reason=f"Timeout removed by {ctx.author}")
    await ctx.send(f"Removed the timeout from {member}.")


@bot.command(name="lock")
@commands.guild_only()
@commands.has_guild_permissions(manage_channels=True)
@commands.bot_has_permissions(manage_channels=True)
async def lock(ctx: commands.Context) -> None:
    """Prevent the default role from sending messages in this channel."""
    await ctx.channel.set_permissions(
        ctx.guild.default_role,
        send_messages=False,
        reason=f"Channel locked by {ctx.author}",
    )
    await ctx.send("This channel is now locked.")


@bot.command(name="unlock")