【发布时间】:2021-05-20 17:59:44
【问题描述】:
我使用:await ctx.send(str(ctx.guild.owner.id)) 或 await ctx.send(ctx.guild.owner.id) 但机器人说“无”。我该如何解决这个问题
【问题讨论】:
标签: python discord.py owner
我使用:await ctx.send(str(ctx.guild.owner.id)) 或 await ctx.send(ctx.guild.owner.id) 但机器人说“无”。我该如何解决这个问题
【问题讨论】:
标签: python discord.py owner
您需要获取discord.Member 对象而不是字符串对象。为此,您可以使用get_member 函数。这是一个将服务器所有者输出到频道的简单函数:
@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}')
【讨论】:
您需要意图才能获取成员的信息。因为ctx.guild.owner 是discord.Member 对象。您需要成员意图。
import discord
from discord.ext import commands
intents= discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix="!", intents=intents)
您还需要从 discord 开发者门户打开意图。
Reference (With guide on how to enable intents)
P.S:在 DM 中运行命令也会返回 None。
【讨论】: