vy_9m.gg

Give me a bot ! Through which i can announce things ! I can create poll ! I can timeout someone / ban / kick ! Prefix = .

Kodari AI
KodariMar 28 at 5:13 am 4,443 (v2)

Iโ€™ll create a Discord moderation and announcement bot with all the requested features.

ModeratorAnnouncementBot
A Discord moderation bot with announcement and poll creation capabilities. Features include server-wide announcements to designated channels, interactive polls with emoji reactions, and comprehensive moderation tools (timeout, kick, ban). Uses "." prefix for all commands. Includes permission checks to ensure only authorized users can execute moderation actions.

โœ… Bot created! Your Discord bot includes:

Commands:

  • .announce #channel message - Send announcements to any channel

  • .poll "question" "option1" "option2" ... - Create polls with up to 10 options

  • .timeout @user duration unit reason - Timeout users (e.g., .timeout @user 10 m Spamming)

  • .kick @user reason - Kick members

  • .ban @user reason - Ban members

Setup:

  1. Install dependencies: pip install -r requirements.txt

  2. Get your bot token from Discord Developer Portal

  3. Replace your_discord_bot_token_here in .env with your actual token

  4. Enable Message Content Intent and Server Members Intent in the Discord Developer Portal

  5. Run: python bot.py

All moderation commands include permission checks and error handling!

Kodari can make mistakes. Review important code before using.
Files
.gitignore
bot.py
requirements.txt
Code
3 182
bot.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
from datetime import timedelta

load_dotenv()

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

bot = commands.Bot(command_prefix='.', intents=intents)

@bot.event
async def on_ready():
    print(f'Bot is ready! Logged in as {bot.user}')
    print(f'Bot ID: {bot.user.id}')
    print('------')

@bot.command(name='announce')
@commands.has_permissions(administrator=True)
async def announce(ctx, channel: discord.TextChannel, *, message):
    embed = discord.Embed(
        title="๐Ÿ“ข Announcement",
        description=message,
        color=discord.Color.blue()
    )
    embed.set_footer(text=f"Announced by {ctx.author.name}", icon_url=ctx.author.avatar.url if ctx.author.avatar else None)
    await channel.send(embed=embed)
    await ctx.send(f"โœ… Announcement sent to {channel.mention}")

@bot.command(name='poll')
@commands.has_permissions(manage_messages=True)
async def poll(ctx, question, *options):
    if len(options) > 10:
        await ctx.send("โŒ You can only have up to 10 options!")
        return
    if len(options) < 2:
        await ctx.send("โŒ You need at least 2 options for a poll!")
        return
    
    emoji_numbers = ['1๏ธโƒฃ', '2๏ธโƒฃ', '3๏ธโƒฃ', '4๏ธโƒฃ', '5๏ธโƒฃ', '6๏ธโƒฃ', '7๏ธโƒฃ', '8๏ธโƒฃ', '9๏ธโƒฃ', '๐Ÿ”Ÿ']
    
    description = []
    for i, option in enumerate(options):
        description.append(f"{emoji_numbers[i]} {option}")
    
    embed = discord.Embed(
        title=f"๐Ÿ“Š {question}",
        description="\n\n".join(description),
        color=discord.Color.green()
    )
    embed.set_footer(text=f"Poll by {ctx.author.name}", icon_url=ctx.author.avatar.url if ctx.author.avatar else None)
    
    poll_message = await ctx.send(embed=embed)
    
    for i in range(len(options)):
        await poll_message.add_reaction(emoji_numbers[i])
    
    await ctx.message.delete()

@bot.command(name='timeout')
@commands.has_permissions(moderate_members=True)
async def timeout(ctx, member: discord.Member, duration: int, unit: str = "m", *, reason: str = "No reason provided"):
    if member.top_role >= ctx.author.top_role and ctx.author != ctx.guild.owner:
        await ctx.send("โŒ You cannot timeout someone with a role equal to or higher than yours!")
        return
    
    if member == ctx.author:
        await ctx.send("โŒ You cannot timeout yourself!")
        return
    
    time_units = {
        's': 1,
        'm': 60,
        'h': 3600,
        'd': 86400
    }
    
    if unit.lower() not in time_units:
        await ctx.send("โŒ Invalid time unit! Use: s (seconds), m (minutes), h (hours), d (days)")
        return
    
    seconds = duration * time_units[unit.lower()]
    
    if seconds > 2419200:
        await ctx.send("โŒ Timeout duration cannot exceed 28 days!")
        return
    
    try:
        await member.timeout(timedelta(seconds=seconds), reason=reason)
        embed = discord.Embed(
            title="โฑ๏ธ Member Timed Out",
            color=discord.Color.orange()
        )
        embed.add_field(name="Member", value=f"{member.mention} ({member})", inline=False)
        embed.add_field(name="Duration", value=f"{duration}{unit}", inline=True)
        embed.add_field(name="Moderator", value=ctx.author.mention, inline=True)
        embed.add_field(name="Reason", value=reason, inline=False)
        await ctx.send(embed=embed)
    except discord.Forbidden:
        await ctx.send("โŒ I don't have permission to timeout this member!")
    except Exception as e:
        await ctx.send(f"โŒ An error occurred: {str(e)}")

@bot.command(name='kick')
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason: str = "No reason provided"):
    if member.top_role >= ctx.author.top_role and ctx.author != ctx.guild.owner:
        await ctx.send("โŒ You cannot kick someone with a role equal to or higher than yours!")
        return
    
    if member == ctx.author:
        await ctx.send("โŒ You cannot kick yourself!")
        return
    
    try:
        await member.kick(reason=reason)
        embed = discord.Embed(
            title="๐Ÿ‘ข Member Kicked",
            color=discord.Color.orange()
        )
        embed.add_field(name="Member", value=f"{member} ({member.id})", inline=False)
        embed.add_field(name="Moderator", value=ctx.author.mention, inline=True)
        embed.add_field(name="Reason", value=reason, inline=False)
        await ctx.send(embed=embed)
    except discord.Forbidden:
        await ctx.send("โŒ I don't have permission to kick this member!")
    except Exception as e:
        await ctx.send(f"โŒ An error occurred: {str(e)}")

@bot.command(name='ban')
@commands.has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, *, reason: str = "No reason provided"):
    if member.top_role >= ctx.author.top_role and ctx.author != ctx.guild.owner:
        await ctx.send("โŒ You cannot ban someone with a role equal to or higher than yours!")
        return
    
    if member == ctx.author:
        await ctx.send("โŒ You cannot ban yourself!")
        return
    
    try:
        await member.ban(reason=reason)
        embed = discord.Embed(
            title="๐Ÿ”จ Member Banned",
            color=discord.Color.red()
        )
        embed.add_field(name="Member", value=f"{member} ({member.id})", inline=False)
        embed.add_field(name="Moderator", value=ctx.author.mention, inline=True)
        embed.add_field(name="Reason", value=reason, inline=False)
        await ctx.send(embed=embed)
    except discord.Forbidden:
        await ctx.send("โŒ I don't have permission to ban this member!")
    except Exception as e:
        await ctx.send(f"โŒ An error occurred: {str(e)}")

@announce.error
@poll.error
@timeout.error
@kick.error
@ban.error
async def command_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send("โŒ You don't have permission to use this command!")
    elif isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(f"โŒ Missing required argument: {error.param.name}")
    elif isinstance(error, commands.BadArgument):
        await ctx.send("โŒ Invalid argument provided!")
    else:
        await ctx.send(f"โŒ An error occurred: {str(error)}")

bot.run(os.getenv('DISCORD_TOKEN'))