【问题标题】:How can i get the server owner name in discord.py如何在 discord.py 中获取服务器所有者名称
【发布时间】: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


【解决方案1】:

您需要获取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}')

【讨论】:

    【解决方案2】:

    您需要意图才能获取成员的信息。因为ctx.guild.ownerdiscord.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

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多