You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would love some help as I've been banging my head against this problem for hours. I am trying to setup my bot to have context menus for selectable parameters. When I run the award or org command, I get the error below.
import os
import logging
import discord
from discord.ext import commands
from dotenv import load_dotenv
import asyncio
import sqlite3
# Load environment variables
load_dotenv()
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
TOKEN = os.getenv("DISCORD_TOKEN")
if not TOKEN:
logging.error("DISCORD_TOKEN environment variable not set.")
raise ValueError("DISCORD_TOKEN environment variable not set.")
# Configure logging
logging.basicConfig(
level=LOG_LEVEL,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.StreamHandler()]
)
logging.info(f"Log level set to {LOG_LEVEL}")
# Set command prefix and intents
PREFIX = '/'
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=PREFIX, intents=intents)
@bot.event
async def on_ready():
logging.info(f"Bot is ready! Logged in as {bot.user}")
try:
synced = await bot.tree.sync()
logging.info(f"Slash commands synced with Discord: {len(synced)} commands.")
except Exception as e:
logging.error(f"Failed to sync slash commands: {e}")
async def load_extensions():
"""Load all bot extensions."""
try:
await bot.load_extension("awards.awards")
logging.info("Awards extension loaded.")
except Exception as e:
logging.error(f"Failed to load awards extension: {e}")
try:
await bot.load_extension("orgs.orgs")
logging.info("Orgs extension loaded.")
except Exception as e:
logging.error(f"Failed to load orgs extension: {e}")
async def main():
"""Main entry point for the bot."""
initialize_database(DB_PATH, INIT_SCRIPTS_DIR)
async with bot:
await load_extensions()
logging.info(f"Loaded extensions: {bot.extensions.keys()}")
await bot.start(TOKEN)
if __name__ == "__main__":
try:
asyncio.run(main())
except Exception as e:
logging.error(f"Failed to start the bot: {e}")
And here's the code for my Awards class defines the awards commands:
from discord import app_commands
from discord.ext import commands
from datetime import datetime
import sqlite3
import discord
from common.load_sql import load_sql
from db.db import conn
class Awards(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.cursor = conn.cursor()
# Create a group for 'award' slash commands
award_group = app_commands.Group(name="award", description="Manage awards")
@award_group.command(name="give", description="Assign an award to a member")
@app_commands.describe(
member="The member to give the award to",
award_type="The type of the award",
reason="The reason for giving the award"
)
async def give(self, interaction: discord.Interaction, member: discord.Member, award_type: str, reason: str):
"""Slash command to assign an award."""
timestamp = datetime.utcnow().isoformat()
sql_query = load_sql("insert_award.sql")
try:
self.cursor.execute(sql_query, (member.id, award_type, reason, timestamp))
conn.commit()
await interaction.response.send_message(
f"🎉 {member.mention} has been awarded the **{award_type}** award!\n**Reason:** {reason}"
)
except sqlite3.Error as e:
await interaction.response.send_message(f"An error occurred while assigning the award: {e}")
@award_group.command(name="list", description="List all awards assigned to a member")
@app_commands.describe(member="The member whose awards you want to list")
async def list(self, interaction: discord.Interaction, member: discord.Member):
"""Slash command to list all awards assigned to a member."""
sql_query = load_sql("list_assigned_awards_for_member.sql")
try:
self.cursor.execute(sql_query, (member.id,))
awards = self.cursor.fetchall()
if not awards:
await interaction.response.send_message(f"{member.mention} has no awards assigned.")
return
award_list = "\n".join([
f"**{award_type}** - {award_count} times (Last Reason: {last_reason or 'No reason'}) "
f"(Last Given: {datetime.fromisoformat(last_given).strftime('%b %d, %Y %I:%M %p')})"
for award_type, award_count, last_reason, last_given in awards
])
await interaction.response.send_message(f"Awards for {member.mention}:\n{award_list}")
except sqlite3.Error as e:
await interaction.response.send_message(f"An error occurred while retrieving awards: {e}")
async def setup(bot):
await bot.add_cog(Awards(bot))
Any help greatly appreciated. I haven't really been able to find a solution here or on SO.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
Would love some help as I've been banging my head against this problem for hours. I am trying to setup my bot to have context menus for selectable parameters. When I run the
award
ororg
command, I get the error below.Here is the log output
Here's the code for main.py:
And here's the code for my Awards class defines the awards commands:
Any help greatly appreciated. I haven't really been able to find a solution here or on SO.
Beta Was this translation helpful? Give feedback.
All reactions