I use: await ctx.send(str(ctx.guild.owner.id)) or await ctx.send(ctx.guild.owner.id) but the bot say 'None'. How can i fix this
You'll need to get a discord.Member
object instead of a string object. To do this, you can use the get_member
function. Here is a simple function to output the server's owner to the channel:
@client.command()
async def owner_find(ctx):
guild_owner = client.get_user(int(ctx.guild.owner.id))
await ctx.send(f'The owner of this server is: {guild_owner}')
You need intents in order to get the member's info. Since ctx.guild.owner
is discord.Member
object. You need member intents.
import discord
from discord.ext import commands
intents= discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix="!", intents=intents)
You also need to turn on intents from discord developer portal.
Reference (With guide on how to enable intents)
PS: Running command in DMs also returns None
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.