fix(commands/voice/queue): lock when queue_or_play

This commit is contained in:
Ryan 2024-12-30 18:06:47 -05:00
parent 73c1ebf9ee
commit 393403ef7d
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
3 changed files with 10 additions and 4 deletions

View File

@ -63,7 +63,7 @@ async def queue_or_play(message):
not message.guild.voice_client.is_playing() not message.guild.voice_client.is_playing()
and not message.guild.voice_client.is_paused() 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) play_next(message)
else: else:
await utils.reply( await utils.reply(

View File

@ -1,3 +1,4 @@
import asyncio
import contextlib import contextlib
import importlib import importlib
import inspect import inspect
@ -11,6 +12,7 @@ import commands
import constants import constants
import core import core
import utils import utils
from state import command_locks
async def on_message(message): async def on_message(message):
@ -93,7 +95,10 @@ async def on_message(message):
case C.LEAVE: case C.LEAVE:
await commands.voice.leave(message) await commands.voice.leave(message)
case C.QUEUE | C.PLAY: 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: case C.SKIP:
await commands.voice.skip(message) await commands.voice.skip(message)
case C.RESUME: case C.RESUME:

View File

@ -2,11 +2,12 @@ import time
import disnake import disnake
start_time = time.time()
player_queue = {} player_queue = {}
player_current = {} player_current = {}
command_locks = {}
intents = disnake.Intents.default() intents = disnake.Intents.default()
intents.message_content = True intents.message_content = True
client = disnake.Client(intents=intents) client = disnake.Client(intents=intents)
start_time = time.time()