From 393403ef7d8946df21121004eeba4a6a7467dee6 Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Mon, 30 Dec 2024 18:06:47 -0500 Subject: [PATCH] fix(commands/voice/queue): lock when queue_or_play --- commands/voice.py | 2 +- core.py | 7 ++++++- state.py | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/commands/voice.py b/commands/voice.py index ce7f38f..cbcb544 100644 --- a/commands/voice.py +++ b/commands/voice.py @@ -63,7 +63,7 @@ async def queue_or_play(message): not message.guild.voice_client.is_playing() and not message.guild.voice_client.is_paused() ): - await message.channel.send(f"**now playing:** `{player.title}`") + await utils.reply(message, f"**now playing:** `{player.title}`") play_next(message) else: await utils.reply( diff --git a/core.py b/core.py index 08e5cd5..ab805ae 100644 --- a/core.py +++ b/core.py @@ -1,3 +1,4 @@ +import asyncio import contextlib import importlib import inspect @@ -11,6 +12,7 @@ import commands import constants import core import utils +from state import command_locks async def on_message(message): @@ -93,7 +95,10 @@ async def on_message(message): case C.LEAVE: await commands.voice.leave(message) case C.QUEUE | C.PLAY: - await commands.voice.queue_or_play(message) + if message.guild.id not in command_locks: + command_locks[message.guild.id] = asyncio.Lock() + async with command_locks[message.guild.id]: + await commands.voice.queue_or_play(message) case C.SKIP: await commands.voice.skip(message) case C.RESUME: diff --git a/state.py b/state.py index 847e2a0..9ab6bd9 100644 --- a/state.py +++ b/state.py @@ -2,11 +2,12 @@ import time import disnake -start_time = time.time() - player_queue = {} player_current = {} +command_locks = {} intents = disnake.Intents.default() intents.message_content = True client = disnake.Client(intents=intents) + +start_time = time.time()