【问题标题】:discord.py is only sending "objects" rather than actual informationdiscord.py 只发送“对象”而不是实际信息
【发布时间】:2020-09-11 10:17:16
【问题描述】:

问题出在这里:

这是我的代码:

if message.content.startswith("%guildinfo"):
        embed = discord.Embed(title="Guild Info: " + str(Guild.name), color=0xff00ae)
        embed.add_field(name="Owned Emojis: ", value=Guild.emojis)
        embed.add_field(name="Icon: ", value=Guild.icon)
        embed.add_field(name="ID: ", value=Guild.id)
        embed.add_field(name="Owner's ID: ", value=Guild.owner)
        embed.add_field(name="Max Members: ", value=Guild.max_members)
        embed.add_field(name="Banner: ", value=Guild.banner)
        embed.add_field(name="Description: ", value=Guild.description)
        embed.add_field(name="Splash: ", value=Guild.splash)
        embed.add_field(name="How many boosters? ", value=Guild.premium_subscription_count)
        embed.add_field(name="Channel List: ", value=Guild.channels)
        embed.add_field(name="Voice Channels: ", value=Guild.voice_channels)
        embed.add_field(name="Texr Channels: ", value=Guild.text_channels)
        embed.add_field(name="Max # of Emojis: ", value=Guild.emoji_limit)
        embed.add_field(name="Max Filesize: ", value=Guild.filesize_limit)
        embed.add_field(name="Members: ", value=Guild.members)
        embed.add_field(name="# of Members: ", value=Guild.member_count)
        embed.add_field(name="Created at: ", value=Guild.created_at)
        await message.channel.send(embed=embed)

很清楚,我想要的是发送实际信息而不是这些对象。

【问题讨论】:

  • 我的猜测是 Guild. 对象没有显示对象值的 to string 方法。它们本身可能有其他方法或属性。
  • 您是如何获得 Guild 对象的?您确定它是特定公会的实例还是公会类?
  • 我假设您想显示与消息所属的公会相关的信息。如果是这样,您可以使用message.guild 获取此信息。如果不是,请编辑您的问题,使您的代码为minimal reproducible example。一方面,我们不知道Guild 是什么。

标签: python bots discord discord.py


【解决方案1】:

“公会”不是一个对象,而是一个类。

class discord.Guild

因此,在 Guild 的字段上使用 str() 不会返回任何值,而是返回有关类属性的信息。 我建议您使用

正确实例化 Class Guild 的对象
my_guild = Bot.get_guild(id)   (pseudo-code)

您可以在the docs 中找到有关此例程的更多信息,并访问如下信息:

my_guild.name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 2021-08-11
    • 2020-11-10
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多