Files
bot.py
requirements.txt
Code
2 88
bot.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
import logging
load_dotenv()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('PortfolioBot')
intents = discord.Intents.default()
intents.message_content = True
intents.guilds = True
bot = commands.Bot(command_prefix='!', intents=intents)
PORTFOLIO_CHANNEL_ID = None
@bot.event
async def on_ready():
logger.info(f'Bot is ready! Logged in as {bot.user}')
logger.info(f'Bot ID: {bot.user.id}')
@bot.command(name='setportfolio')
@commands.has_permissions(administrator=True)
async def set_portfolio_channel(ctx, channel: discord.TextChannel):
global PORTFOLIO_CHANNEL_ID
PORTFOLIO_CHANNEL_ID = channel.id
await ctx.send(f'✅ Portfolio channel set to {channel.mention}')
@bot.command(name='thumbnail')
async def submit_thumbnail(ctx, url: str = None, *, title: str = None):
if PORTFOLIO_CHANNEL_ID is None:
await ctx.send('❌ Portfolio channel not set! Ask an admin to use `!setportfolio #channel`')
return
portfolio_channel = bot.get_channel(PORTFOLIO_CHANNEL_ID)
if portfolio_channel is None:
await ctx.send('❌ Portfolio channel not found!')
return
if url is None and not ctx.message.attachments:
await ctx.send('❌ Please provide an image URL or attach an image!')
return
image_url = url if url else ctx.message.attachments[0].url
embed = discord.Embed(
title=title if title else f"Thumbnail by {ctx.author.display_name}",
color=discord.Color.blue()
)
embed.set_image(url=image_url)
embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar.url if ctx.author.avatar else None)
embed.set_footer(text=f"Submitted from #{ctx.channel.name}")
try:
await portfolio_channel.send(embed=embed)
await ctx.send(f'✅ Thumbnail sent to {portfolio_channel.mention}!')
except discord.HTTPException as e:
await ctx.send(f'❌ Failed to send thumbnail: {str(e)}')
@bot.command(name='portfolioinfo')
async def portfolio_info(ctx):
if PORTFOLIO_CHANNEL_ID is None:
await ctx.send('ℹ️ No portfolio channel is currently set.')
else:
channel = bot.get_channel(PORTFOLIO_CHANNEL_ID)
if channel:
await ctx.send(f'ℹ️ Current portfolio channel: {channel.mention}')
else:
await ctx.send('ℹ️ Portfolio channel is set but not found.')
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send('❌ You do not have permission to use this command.')
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send(f'❌ Missing required argument. Use `!help {ctx.command.name}` for more info.')
elif isinstance(error, commands.BadArgument):
await ctx.send('❌ Invalid argument provided.')
else:
logger.error(f'Error in command {ctx.command}: {error}')
await ctx.send(f'❌ An error occurred: {str(error)}')
bot.run(os.getenv('DISCORD_TOKEN'))