botsdiscord.pyctx

How to set guild_subscriptions event to true in discord.py?


I am facing a problem in discord.py, the following code is running perfectly, but ctx.guild.owner returns none, and in documentation it says that if this happens the event guild_subscriptions is set to False, how can I set this event to True in order to make it work? I can't find any solution in discord.py documentation, neither Google.

The code of my serverstats command:

@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)

Solution

  • the event guild_subscriptions is set to False

    I can't find any solution in discord.py documentation

    It's not an event. The docs say it's a parameter when creating a commands.Bot instance, and that you can find in the documentation for Clients, which you can. If you scroll down to the bottom of that list of parameters, you'll see guild_subscriptions(bool), which is what you're looking for.

    To enable this, all you have to do is add it to the code where you create your Client:

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

    Also, since Discord 1.5 you now need to pass the correct Intents, and the documentation for Client states that you need to have Intents.members enabled if you don't want guild.owner to return None, which is also what's causing your issue. You also have to pass these intents as a parameter, so the final thing would end up looking something like this:

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