此代码未给出错误,也不会回复。我不明白。
@client.command()
async def serverinfo(ctx, guild: discord.Guild = None):
guild = ctx.guild
embed = discord.Embed(title=f'{guild} sunucusunun bilgileri',description="Coded by Amazoen#1907",timestamp=ctx.message_created_at,color=discord.Color.red())
embed.set_thumbnail(url=guild.icon)
embed.add_field(name="Kanal Sayısı:",value=len(guild.channels))
embed.add_field(name="Rol Sayısı:",value=len(guild.roles))
embed.add_field(name="Booster Sayısı:",value=guild.premium_subscription_count)
embed.add_field(name="Üye Sayısı:",value=guild.member_count)
embed.add_field(name="Kuruluş Tarihi:",value=guild.created_at)
embed.add_field(name="Sunucu Sahibi:",value=guild.owner)
embed.set_footer(text=f"Komut {ctx.author} tarafından kullanıldı.",icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
答案 0 :(得分:0)
这些是您的代码中有错误的地方:
ctx.guild
而不是ctx.message.guild
。len()
的方式不太正确。guild.icon
来代替guild.icon_url
这是决赛的样子-@client.command()
async def testserverinfo(ctx, guild: discord.Guild = None):
guild = ctx.message.guild
roles =[role for role in guild.roles]
text_channels = [text_channels for text_channels in guild.text_channels]
embed = discord.Embed(title=f'{guild.name} sunucusunun bilgileri', description="Coded by VideroDesigns.#9999", timestamp=ctx.message.created_at, color=discord.Color.red())
embed.set_thumbnail(url=guild.icon_url)
embed.add_field(name="Kanal Sayısı:", value=f"{len(text_channels)}")
embed.add_field(name="Rol Sayısı:", value=f"{len(roles)}")
embed.add_field(name="Booster Sayısı:", value=guild.premium_subscription_count)
embed.add_field(name="Üye Sayısı:", value=guild.member_count)
embed.add_field(name="Kuruluş Tarihi:", value=guild.created_at)
embed.add_field(name="Sunucu Sahibi:", value=guild.owner)
embed.set_footer(text=f"Komut {ctx.author} tarafından kullanıldı.", icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
答案 1 :(得分:0)
问题如下:
您使用ctx.message_created_at
而不是ctx.message.created_at
。
ctx.message.created_at
即可解决该问题。)另一个问题是您使用guild.icon
而不是guild.icon_url
。
因此,解决这两个问题可使您的代码可执行:
async def serverinfo(ctx, guild: discord.Guild = None):
guild = ctx.guild
embed = discord.Embed(title=f'{guild} sunucusunun bilgileri', description="Coded by Amazoen#1907",
timestamp=ctx.message.created_at, color=discord.Color.red())
embed.set_thumbnail(url=guild.icon_url)
embed.add_field(name="Kanal Sayısı:", value=len(guild.channels))
embed.add_field(name="Rol Sayısı:", value=len(guild.roles))
embed.add_field(name="Booster Sayısı:", value=guild.premium_subscription_count)
embed.add_field(name="Üye Sayısı:", value=guild.member_count)
embed.add_field(name="Kuruluş Tarihi:", value=guild.created_at)
embed.add_field(name="Sunucu Sahibi:", value=guild.owner)
embed.set_footer(text=f"Komut {ctx.author} tarafından kullanıldı.", icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
但是我还有一件事要提到。
您可以在函数输入, guild: discord.Guild = None
中使用此行。
请注意,稍后您将定义一个具有相同名称“ guild” guild = ctx.guild
的新变量。
通过这样做,您不会使用在函数输入中创建的变量。使函数输入中定义的那个无效。
我建议将其更新为此(因为这样做是一样的,并且用更少的无用代码完成):
async def serverinfo(ctx):
guild = ctx.guild
embed = discord.Embed(title=f'{guild} sunucusunun bilgileri', description="Coded by Amazoen#1907",
timestamp=ctx.message.created_at, color=discord.Color.red())
embed.set_thumbnail(url=guild.icon_url)
embed.add_field(name="Kanal Sayısı:", value=len(guild.channels))
embed.add_field(name="Rol Sayısı:", value=len(guild.roles))
embed.add_field(name="Booster Sayısı:", value=guild.premium_subscription_count)
embed.add_field(name="Üye Sayısı:", value=guild.member_count)
embed.add_field(name="Kuruluş Tarihi:", value=guild.created_at)
embed.add_field(name="Sunucu Sahibi:", value=guild.owner)
embed.set_footer(text=f"Komut {ctx.author} tarafından kullanıldı.", icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
参考: