【问题标题】:How to set guild_subscriptions event to true in discord.py?如何在 discord.py 中将 guild_subscriptions 事件设置为 true?
【发布时间】:2021-02-07 13:23:49
【问题描述】:

我在 discord.py 中遇到问题,以下代码运行良好,但 ctx.guild.owner 没有返回任何内容,并且在文档中说如果发生这种情况,事件 guild_subscriptions 设置为 False,怎么能我将此事件设置为True 以使其正常工作?我在 discord.py 文档中找不到任何解决方案,Google 也没有。

我的serverstats命令代码:

@commands.command(name="serverstats", aliases = ["serverinfo", "si", "ss", "check-stats", 'cs'])
    async def serverstats(self, ctx: commands.Context):

        embed = discord.Embed(
            color = discord.Colour.orange(),
            title = f"{ctx.guild.name}")


        embed.set_thumbnail(url = f"{ctx.guild.icon_url}")
        embed.add_field(name = "ID", value = f"{ctx.guild.id}")
        embed.add_field(name = "????Owner", value = f"{ctx.guild.owner}")
        embed.add_field(name = "????Region", value = f"{ctx.guild.region}")
        embed.add_field(name = "????Member Count", value = f"{ctx.guild.member_count}")
        embed.add_field(name = "????Created at", value = f"{ctx.guild.created_at}")
        embed.set_footer(icon_url = f"{ctx.author.avatar_url}", text = f"Requested by {ctx.author.name}")

        await ctx.send(embed=embed)

【问题讨论】:

    标签: bots discord.py ctx


    【解决方案1】:

    事件 guild_subscriptions 设置为 False

    我在 discord.py 文档中找不到任何解决方案

    这不是一个事件。文档说它是创建commands.Bot instance 时的一个参数,您可以在can 的客户端文档中找到它。如果您向下滚动到该参数列表的底部,您将看到 guild_subscriptions(bool),这就是您要查找的内容。

    要启用此功能,您只需将其添加到您创建客户端的代码中:

    client = commands.Bot(command_prefix=your_prefix, guild_subscriptions=True) 
    

    此外,从 Discord 1.5 开始,您现在需要传递正确的 Intents,并且客户端的文档指出,如果您不希望 guild.owner 返回 None,则需要启用 Intents.members,这也是导致您的问题的原因。您还必须将这些意图作为参数传递,所以最终的结果会是这样的:

    # Configure intents (1.5.0)
    intents = discord.Intents.default()
    intents.members = True
    client = commands.Bot(command_prefix=your_prefix, guild_subscriptions=True, intents=intents) 
    

    【讨论】:

    • 非常感谢您的帮助!我真的很欣赏它!现在可以了!
    猜你喜欢
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 2021-10-23
    相关资源
    最近更新 更多