首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果在4分钟后打开机器人,按钮停止工作,我该怎么办?

如果在4分钟后打开机器人,按钮停止工作,我该怎么办?
EN

Stack Overflow用户
提问于 2022-11-20 18:14:45
回答 1查看 26关注 0票数 0

我在用不和谐的声音在蟒蛇上制造一个不和谐的机器人。以下是导入:从随机导入的导入不和谐,从discord.ext导入json命令,从discord.User接口导入按钮,视图

下面是一个按钮的示例:

代码语言:javascript
复制
class ButtonSandStone8(Button):
    def __init__(self,label):
        super().__init__(label=label,style=discord.ButtonStyle.grey,custom_id='SandStone_btn8')

    async def callback(self, interaction):
        global queue8
        if "<@" + str(interaction.user.id) + ">" + "\n"+ "\n"+ "\n" in queue8:
            global lobby_voice8
            global ct8
            global t8
            global voice_ct8
            global voice_t8
            voice_state = interaction.user.voice

            if voice_state is None:
                embed = discord.Embed(description='Вы должны зайти в войс, чтобы участвовать!',color=discord.Color.dark_grey())
                return await interaction.response.send_message(embed=embed, ephemeral=True)

            elif interaction.user.voice.channel.id == lobby_voice8:
                global voices8
                if len(queue8)-10 < 10:
                    embed = discord.Embed(description='Очередь не полная!',color=discord.Color.dark_grey())
                    await interaction.response.send_message(embed=embed, ephemeral=True)

                elif len(queue8)-10 == 10 and interaction.user not in voices8 and "<@" + str(interaction.user.id) + ">" + "\n"+ "\n"+ "\n" in queue8:
                    voices8.append(interaction.user)
                    global SandStone8
                    global Rust8
                    global Zone98
                    global Province8
                    global Breeze8
                    SandStone8 += 1
                    if len(voices8) < 10:
                        embed = discord.Embed(description='+1 голос за карту SandStone', color=discord.Color.dark_grey())
                        await interaction.response.send_message(embed=embed, ephemeral=True)

                    if len(voices8) == 10:
                        global msg8
                        await msg8.delete()
                        if SandStone8 > Rust8 and SandStone8 > Zone98 and SandStone8 > Breeze8 and SandStone8 > Province8:
                            await distribution_sandstone8(interaction)

                        elif Rust8 > SandStone8 and Rust8 > Zone98 and Rust8 > Breeze8 and Rust8 > Province8:
                            await distribution_rust8(interaction)

                        elif Zone98 > SandStone8 and Zone98 > Rust8 and Zone98 > Province8 and Zone98 > Breeze8:
                            await distribution_zone98(interaction)

                        elif Province8 > SandStone8 and Province8 > Rust8 and Province8 > Zone98 and Province8 > Breeze8:
                            await distribution_province8(interaction)

                        elif Breeze8 > SandStone8 and Breeze8 > Rust8 and Breeze8 > Zone98 and Breeze8 > Province8:
                            await distribution_breeze8(interaction)

                        else:
                            voices8.clear()
                            SandStone8 = 0
                            Rust8 = 0
                            Zone98 = 0
                            Province8 = 0
                            Breeze8 = 0
                            embed = discord.Embed(description='Ничья! Голосование повторяется', color=discord.Color.dark_grey())
                            await interaction.response.send_message(embed=embed, delete_after=180)

            else:
                embed = discord.Embed(description='Вы подключены не к тому голосовому каналу!',color=discord.Color.dark_grey())
                await interaction.response.send_message(embed=embed, ephemeral=True)

        else:
            embed = discord.Embed(description='Вас нет в очереди чтобы голосовать!',color=discord.Color.red())
            await interaction.response.send_message(embed=embed, ephemeral=True)

下面是一个按钮调用的示例:

代码语言:javascript
复制
SandStone_btn8 = ButtonSandStone8("1.SandStone")
w = View()
w.add_item(SandStone_btn8)

我的想法是每3分钟重新启动一次机器人,但也许还有另一种方法来修复它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-20 19:58:33

timeout kwarg到View的默认值是180,这意味着视图在180秒后超时。如果您想要不同的超时,请为它传递一个值。None值意味着它不会超时。

代码语言:javascript
复制
View(timeout=None)

博士:https://discordpy.readthedocs.io/en/stable/interactions/api.html?highlight=view#discord.ui.View.timeout

在不再接受输入之前,以秒为单位从上次与UI的交互开始超时。如果没有,那么就没有超时。

但是,这只是在您的bot正在运行的情况下,并且当您重新启动bot时,所有组件都将停止工作。如果您想避免这种情况,有一个关于如何生成持久视图的正式示例。https://github.com/Rapptz/discord.py/blob/master/examples/views/persistent.py

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74510696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档