Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将计票添加到反应中?_Python_Discord_Discord.py_Discord.py Rewrite - Fatal编程技术网

Python 如何将计票添加到反应中?

Python 如何将计票添加到反应中?,python,discord,discord.py,discord.py-rewrite,Python,Discord,Discord.py,Discord.py Rewrite,嗨,我正在研究一个音乐齿轮,我正在研究如何做一个简单的跳过投票 我试图实现的是,当4个成员用skip反应if control==“skip”:⏩ 它将跳过这首歌 以下是我正在研究的内容,让您更好地了解我在这里要做的事情 async def buttons_controller(self, guild, current, source, channel, context): vc = guild.voice_client vctwo = context.voice_client

嗨,我正在研究一个音乐齿轮,我正在研究如何做一个简单的跳过投票

我试图实现的是,当4个成员用skip反应
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\nYour check for the total votes is checking the wrong variable and returning a constant value:

if control == 'skip':
    total_votes = len(control)
    if total_votes >= 3:
        vc.stop()
        await channel.send('Skip vote passed, skipping song...')
异步定义按钮\u控制器(自身、公会、当前、源、频道、上下文):
vc=guild.voice\u客户端
vctwo=context.voice\u客户端
对于在self.button中进行反应:
等待当前。添加_反应(str(react))
def检查(r,u):
如果不是最新的:
返回错误
elif str(r)不在self.buttons.keys()中:
返回错误
elif u.id==self.bot.user.id或r.message.id!=当前id:
返回错误
elif u不在vc.channel.members中:
返回错误
elif u.bot:
返回错误
返回真值
当前:
如果vc为无:
返回错误
react,user=wait self.bot.wait_for('reaction_add',check=check)
control=self.buttons.get(str(react))
如果控件='rp':
如果vc.已暂停():
vc.resume()
其他:
vc.pause()
如果控件==“跳过”:
总票数=len(对照)
如果总票数>=3:
停止
等待频道。发送('跳过投票通过,跳过歌曲…')
如果控件==“停止”:
mods=get(guild.roles,name=“mods”)
对于列表中的成员(公会成员):
如果mods在member.roles中:
wait context.invoke(self.bot.get_命令(“stop”))
返回
其他:
wait channel.send('只有mod可以停止并清除队列。请尝试跳过歌曲。',在=5之后删除_)
如果控件='vol_up':
player=self.\u cog.get\u player(上下文)
vctwo.source.volume+=2.5
如果控件=='vol_down':
player=self.\u cog.get\u player(上下文)
vctwo.source.volume-=2.5
如果控件==“缩略图”:
wait channel.send(embed=discord.embed(color=0x17FD6E)。set_image(url=source.缩略图)。set_footer(text=f“请求者:{source.requester}}视频缩略图:{source.title}”,icon_url=source.requester.avatar_url),delete_after=10)
如果控件==“教程”:

wait channel.send(embed=discord.embed(color=0x17FD6E)。添加_字段(name=“如何使用音乐控制器?”,value=”⏯ - 暂停\n⏭ - 跳过\n➕ - 增加音量\n➖ - 增加音量\n您对总票数的检查是检查错误的变量并返回一个常量值:

react, user = await self.bot.wait_for('reaction_add', check=check)
control
中定义为
'skip'
(因为否则
control=='skip'
不会计算为true)。因此
len(control)
为4(字符串中有4个字符
'skip'
)。要检查该类型的实际反应数,您需要检查以下行中返回的反应数:


react
是反应对象,API声明它持有反应发送次数的属性
count
。使用该属性,替换行
total\u vots=len(控制)
使用
total\u vows=react.count
获取发送反应的实际次数。

total\u vows=len(控制)
:您的
if
语句(
if control='skip'
)这意味着
control
是一个字符串:因此,
total_voces
在这个块中始终是4。问题是当一个成员跳过它时,它没有达到阈值4,它只会跳过1个反应。是的,这是因为我之前的评论。
total_voces
被设置为控制长度,而控制是string
skip
,长度为4。您能给我举个例子吗?我不知道如何防止这种情况发生。我看不到您的完整代码,但是您需要一种可以计算反应量的方法。可能是
react.count
,但这可能取决于您使用的discord.py的版本ng