changed a few things

This commit is contained in:
2025-03-22 00:01:08 +01:00
parent fe2028fd34
commit b2efff954d
+18 -3
View File
@@ -1,4 +1,3 @@
import asyncio
import discord
from discord.ext import commands, tasks
@@ -13,7 +12,7 @@ from os import environ as env
TOKEN = env['TOKEN']
MINUTES = 30
ROLE = int(env['ROLE'])
CHANNEL = int(env['CHANNEL_ID'])
CHANNEL = None # Global variable
def decode(value):
return b64decode(value).decode('utf-8')
@@ -28,15 +27,26 @@ bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
global CHANNEL # Fixing scope issue
print(f"Logged in as {bot.user}")
CHANNEL = bot.get_channel(int(env['CHANNEL_ID']))
if CHANNEL is None:
print("Error: Channel ID is invalid or bot lacks permissions.")
return
await send_trivia()
check_inactivity.start()
check_inactivity.start() # Now starts only if CHANNEL is valid
active_trivia = {} # Format: {message_id: {"correct_answer": answer, "count": 0}}
@tasks.loop(seconds=150)
async def check_inactivity():
global CHANNEL
if CHANNEL is None:
print("Error: CHANNEL is None, skipping inactivity check.")
return
if ROLE is not None:
current_time = datetime.now(timezone.utc)
print(f"{current_time.strftime('%H:%M:%S')} - Running inactivity check")
@@ -76,6 +86,11 @@ async def on_message(message):
print(f"{datetime.now(timezone.utc).strftime('%H:%M:%S')} - Removed trivia question ID {message.reference.message_id} after {trivia_data['max_replies']} replies")
async def send_trivia():
global CHANNEL
if CHANNEL is None:
print("Error: CHANNEL is None, cannot send trivia.")
return
print(f"{datetime.now(timezone.utc).strftime('%H:%M:%S')} - Channel is inactive, sending message")
current_question = requests.get(OPENTDB_URL).json()['results'][0]