changed a few things
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
@@ -13,7 +12,7 @@ from os import environ as env
|
|||||||
TOKEN = env['TOKEN']
|
TOKEN = env['TOKEN']
|
||||||
MINUTES = 30
|
MINUTES = 30
|
||||||
ROLE = int(env['ROLE'])
|
ROLE = int(env['ROLE'])
|
||||||
CHANNEL = int(env['CHANNEL_ID'])
|
CHANNEL = None # Global variable
|
||||||
|
|
||||||
def decode(value):
|
def decode(value):
|
||||||
return b64decode(value).decode('utf-8')
|
return b64decode(value).decode('utf-8')
|
||||||
@@ -28,15 +27,26 @@ bot = commands.Bot(command_prefix="!", intents=intents)
|
|||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
|
global CHANNEL # Fixing scope issue
|
||||||
print(f"Logged in as {bot.user}")
|
print(f"Logged in as {bot.user}")
|
||||||
CHANNEL = bot.get_channel(int(env['CHANNEL_ID']))
|
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()
|
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}}
|
active_trivia = {} # Format: {message_id: {"correct_answer": answer, "count": 0}}
|
||||||
|
|
||||||
@tasks.loop(seconds=150)
|
@tasks.loop(seconds=150)
|
||||||
async def check_inactivity():
|
async def check_inactivity():
|
||||||
|
global CHANNEL
|
||||||
|
if CHANNEL is None:
|
||||||
|
print("Error: CHANNEL is None, skipping inactivity check.")
|
||||||
|
return
|
||||||
|
|
||||||
if ROLE is not None:
|
if ROLE is not None:
|
||||||
current_time = datetime.now(timezone.utc)
|
current_time = datetime.now(timezone.utc)
|
||||||
print(f"{current_time.strftime('%H:%M:%S')} - Running inactivity check")
|
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")
|
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():
|
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")
|
print(f"{datetime.now(timezone.utc).strftime('%H:%M:%S')} - Channel is inactive, sending message")
|
||||||
current_question = requests.get(OPENTDB_URL).json()['results'][0]
|
current_question = requests.get(OPENTDB_URL).json()['results'][0]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user