aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-11-19 22:36:06 -0600
committerParker <contact@pkrm.dev>2024-11-19 22:36:06 -0600
commit082ca714a146ac956a82611755264e3268e05233 (patch)
treed13effe6746180314243b66b4421ae8c58624551
parentf25d05ec4228713e6cdd68bb393a71d93078028d (diff)
`bot.lavalink = None` if no connection is made
-rw-r--r--code/cogs/music.py8
-rw-r--r--code/cogs/owner/stats.py18
2 files changed, 22 insertions, 4 deletions
diff --git a/code/cogs/music.py b/code/cogs/music.py
index f3e98b4..0bed94b 100644
--- a/code/cogs/music.py
+++ b/code/cogs/music.py
@@ -1,8 +1,8 @@
import discord
from discord.ext import commands
-from discord import app_commands
import lavalink
from lavalink import errors
+from discord.ext import tasks
from utils.config import (
LAVALINK_HOST,
@@ -111,10 +111,12 @@ class Music(commands.Cog):
try:
await node.get_version()
except lavalink.errors.ClientError:
+ self.bot.lavalink = None
LOG.error(
"Authentication to lavalink node failed. Check your login"
" credentials."
)
+ return
else:
await node.connect()
LOG.info(f"Connected to lavalink node {node.name}")
@@ -128,6 +130,10 @@ class Music(commands.Cog):
async def create_player(interaction: discord.Interaction):
"""Create a player for the guild associated with the interaction, or raise an error"""
+ if not interaction.client.lavalink:
+ LOG.error("Lavalink is not connected.")
+ return
+
try:
player = interaction.client.lavalink.player_manager.create(
interaction.guild.id
diff --git a/code/cogs/owner/stats.py b/code/cogs/owner/stats.py
index 5409bfb..04da7ca 100644
--- a/code/cogs/owner/stats.py
+++ b/code/cogs/owner/stats.py
@@ -2,6 +2,7 @@ from discord.ext import commands, tasks
import sqlite3
import discord
import os
+import lavalink
from utils.config import BOT_COLOR, LOG
@@ -80,13 +81,24 @@ class Stats(commands.Cog):
description=(
f"Total Guilds: `{len(self.bot.guilds):,}`\n"
f"Total Commands: `{total_commands:,}`\n\n"
- f"Total Players: `{len(self.bot.lavalink.get_players())}`\n"
- "Load:"
- f" `{round(self.bot.lavalink.nodes[0].stats.lavalink_load * 100, 2)}%`"
),
color=BOT_COLOR,
)
+ # Determine the content of the Lavalink description
+ if self.bot.lavalink:
+ embed.description += (
+ "Total Players:"
+ f" `{len(self.bot.lavalink.get_players())}`\n"
+ "Load:"
+ f" `{round(self.bot.lavalink.nodes[0].stats.lavalink_load * 100, 2)}%`"
+ )
+ else:
+ embed.description += (
+ "Total Players: `NO LAVALINK CONNECTION`\n"
+ "Load: `NO LAVALINK CONNECTION`"
+ )
+
for entry in data:
embed.add_field(
name=entry[0], value=f"` {entry[1]:,} `", inline=True