discord.pyowner

discord.py - why is my serverinfo command showing the owner as "None"?


@client.command()
@commands.guild_only()
async def serverinfo(ctx):
    name = str(ctx.guild.name)
    description = str(ctx.guild.description)

    owner = str(ctx.guild.owner)
    id = str(ctx.guild.id)
    region = str(ctx.guild.region)
    memberCount = str(ctx.guild.member_count)

    icon = str(ctx.guild.icon_url)

    embed = discord.Embed(
        title=name + " Server Information",
        description=description,
        color=discord.Color(0x00000)
    )
    embed.set_thumbnail(url=icon)
    embed.add_field(name="Owner", value=owner, inline=True)
    embed.add_field(name="Server ID", value=id, inline=True)
    embed.add_field(name="Region", value=region, inline=True)
    embed.add_field(name="Member Count", value=memberCount, inline=True)

    await ctx.send(embed=embed)

I tried server member intents but it doesnt work. The bot just outputs the owner field value as "None".


Solution

  • Follow these steps: 1: Update your discord.py version to 1.5.1. 2:Go to https://discord.com/developers/applications. Click on your bot application. 3: Go to the tab labeled Bot and click it. 4: Scroll down until you see Server Members Intent and click it so it is blue. 5: Go to your part of code where there is client/bot = commands.Bot(command_prefix="your prefix here") 6: add this code:

    intents = discord.Intents.default()  
    intents.members = True  
    client/bot = commands.Bot(command_prefix="your prefix here", intents=intents)
    

    This should work perfectly fine. Please reply to this if it doesn't work.