【问题标题】:Is there a way to find out the guild name with only the ID?有没有办法只用ID找出公会名称?
【发布时间】:2020-01-08 23:00:58
【问题描述】:

为了使用我的机器人,我希望服务器需要许可证。这些具有许可证的服务器存储在一个阵列中。不幸的是,这只是ID。现在我想发出一个命令:“& sv-id [ServerID]”。他目前告诉我该 ID 是否在列表中。接下来,他应该把公会的名字发给我。有没有办法通过ID获得公会?该命令作为私人消息发送。我的代码(还没准备好):

if message.author.id == client.AppInfo.owner.id:
    if message.content.startswith(CONFIG.PREFIX + "sv-id"):
        if len(message.content) == 25:
            serverID = message.content[7:25]
            if int(serverID) in CONFIG.AllowedServer:
                guildWithID = client.guilds.id == len(message.content)
                await message.channel.send(":white_check_mark: Server Name: **" + guildWithID.name + "**\n"
                                           "  ServerID: **" + str(serverID) + "**\n")
            else:
                await message.channel.send(":x: Dieser Server existiert nicht, oder ich bin auf diesem Server nicht autorisiert!")

        elif len(message.content) != 25:
            await message.channel.send(":x: Bitte benutze **" + CONFIG.PREFIX + "sv-id [ServerID]**")

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    是的。如果您的机器人在公会中,您可以使用Client.get_guild。否则,您可以使用Client.fetch_guild

    有关按 ID 检索特定模型的详细信息,请参阅the FAQ

    【讨论】:

      【解决方案2】:

      Client.get_guild。我相信它只会获得你的机器人已经加入的公会。

      guild = client.get_guild(id)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-29
        • 1970-01-01
        • 2014-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多