0% found this document useful (0 votes)
32 views2 pages

message

ee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

message

ee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import os

import nextcord
from nextcord.ext import commands
from nextcord import Interaction, SlashOption
import asyncio

intents = nextcord.Intents.default()
intents.messages = True
intents.message_content = True

# Load secrets
token = os.getenv('DISCORD_TOKEN')
channel_ids = [int(id) for id in os.getenv('CHANNEL_IDS', '').split(',') if
id.strip()]
user_ids = [int(id) for id in os.getenv('USER_IDS', '').split(',') if id.strip()]

# Validate variables
if not token:
raise ValueError("DISCORD_TOKEN is not set.")
if not channel_ids:
raise ValueError("CHANNEL_IDS is not set or improperly formatted.")
if not user_ids:
raise ValueError("USER_IDS is not set or improperly formatted.")

bot = commands.Bot(command_prefix="!", intents=intents)

# Register Slash Commands


@bot.slash_command(name="ping", description="Responds with a cool Pong!")
async def ping(interaction: Interaction):
# Get bot latency (response time)
latency = round(bot.latency * 1000) # Convert latency to milliseconds

# Create a cool response with formatting and emojis


response = f"🏓 **Pong!**\nThe bot's latency is: `{latency} ms` 🚀"

# Send the response


await interaction.response.send_message(response)

# /say command: repeats the message provided by the user


@bot.slash_command(name="say", description="Make the bot say something")
async def say(interaction: Interaction, message: str = SlashOption(description="The
message to say")):
# Bot sends the message provided by the user
await interaction.response.send_message(message)

# /embed command: creates an embed with title, description, color, etc.


@bot.slash_command(name="embed", description="Create a custom embed")
async def embed(interaction: Interaction,
title: str = SlashOption(description="Embed title"),
description: str = SlashOption(description="Embed description"),
color: str = SlashOption(description="Embed color (e.g., red,
blue, green)", required=False, default="blue"),
footer: str = SlashOption(description="Footer text",
required=False, default="")):

# Convert color name to discord.Color


color_dict = {
"red": nextcord.Color.red(),
"blue": nextcord.Color.blue(),
"green": nextcord.Color.green(),
"purple": nextcord.Color.purple(),
"yellow": nextcord.Color.gold(),
"orange": nextcord.Color.orange(),
}

embed_color = color_dict.get(color.lower(), nextcord.Color.blue()) # Default


to blue if the color is not found

# Create the embed


embed = nextcord.Embed(title=title, description=description, color=embed_color)

if footer:
embed.set_footer(text=footer)

# Send the embed message


await interaction.response.send_message(embed=embed)

@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")

@bot.event
async def on_message(message):
if message.channel.id in channel_ids:
if not message.pinned and message.author.id not in user_ids:
await asyncio.sleep(0.2)
try:
await message.delete()
except nextcord.HTTPException as e:
print(f"Error deleting message: {e}")
except Exception as e:
print(f"General error: {e}")

await bot.process_commands(message)

bot.run(token)

You might also like