Привет, я работаю над музыкальным винтиком и выясняю, как сделать простое голосование с пропуском.
Я пытаюсь добиться того, чтобы, когда 4 участника отреагировали реакцией скипа if control == 'skip':
⏩, она пропустила песню.
Вот то, с чем я работаю, чтобы лучше понять, что я пытаюсь сделать здесь.
async def buttons_controller(self, guild, current, source, channel, context):
vc = guild.voice_client
vctwo = context.voice_client
for react in self.buttons:
await current.add_reaction(str(react))
def check(r, u):
if not current:
return False
elif str(r) not in self.buttons.keys():
return False
elif u.id == self.bot.user.id or r.message.id != current.id:
return False
elif u not in vc.channel.members:
return False
elif u.bot:
return False
return True
while current:
if vc is None:
return False
react, user = await self.bot.wait_for('reaction_add', check=check)
control = self.buttons.get(str(react))
if control == 'rp':
if vc.is_paused():
vc.resume()
else:
vc.pause()
if control == 'skip':
total_votes = len(control)
if total_votes >= 3:
vc.stop()
await channel.send('Skip vote passed, skipping song...')
if control == 'stop':
mods = get(guild.roles, name="Mods")
for member in list(guild.members):
if mods in member.roles:
await context.invoke(self.bot.get_command("stop"))
return
else:
await channel.send('Only a mod can stop and clear the queue. Try skipping the song instead.', delete_after=5)
if control == 'vol_up':
player = self._cog.get_player(context)
vctwo.source.volume += 2.5
if control == 'vol_down':
player = self._cog.get_player(context)
vctwo.source.volume -= 2.5
if control == 'thumbnail':
await channel.send(embed=discord.Embed(color=0x17FD6E).set_image(url=source.thumbnail).set_footer(text=f"Requested By: {source.requester} | Video Thumbnail: {source.title}", icon_url=source.requester.avatar_url), delete_after=10)
if control == 'tutorial':
await channel.send(embed=discord.Embed(color=0x17FD6E).add_field(name="How to use the music controller?", value="⏯ - Pause\n⏭ - Skip\n➕ - Increase Volume\n➖ - Increase Volume\n? - Get Thumbnail\n⏹ - Stop & Leave\nℹ - Queue\n❔ - Display help for music controls"), delete_after=10)
if control == 'queue':
await self._cog.queue_info(context)
try:
await current.remove_reaction(react, user)
except discord.HTTPException:
pass
Я смотрю на эту часть кода if control == 'skip':
, которая по реакции пропускает воспроизведение песни или, если ни одна песня в очереди не останавливается, воспроизведение песни.
vc.stop()
thisприказывает игроку остановиться и, если другая песня находится в очереди, он будет воспроизводить следующую песню, в противном случае останавливается, если в очереди больше нет песен.
Я пробовал эту функцию, но она не работает для меня.
if control == 'skip':
total_votes = len(control)
if total_votes >= 3:
vc.stop()
await channel.send('Skip vote passed, skipping song...')
Если кто-нибудь может сказать мне, где я иду не так, я бы оценил это.Пример или какой-либо вклад в это было бы здорово.