discord.py - 我的服务器信息命令没有回复
discord.py - my server info command doesn't reply
此代码不报错也不回复。没看懂。
@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)
这些是您的代码中的错误:
- 而不是
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)
问题如下:
您使用 ctx.message_created_at
而不是 ctx.message.created_at
。
- 在文档中您会看到 ctx 对象没有 message_created_at 字段。因为这是未知的程序 returns 一个错误。 (这很可能是打字错误,因此将其修复为
ctx.message.created_at
即可解决该问题。)
另一个问题是您使用 guild.icon
而不是 guild.icon_url
。
- 您需要使用 url 的原因是嵌入的消息无法处理图像。它需要 urls 来代替图像。
因此,解决这两个问题会使您的代码可执行:
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)
参考文献:
此代码不报错也不回复。没看懂。
@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)
这些是您的代码中的错误:
- 而不是
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)
问题如下:
您使用 ctx.message_created_at
而不是 ctx.message.created_at
。
- 在文档中您会看到 ctx 对象没有 message_created_at 字段。因为这是未知的程序 returns 一个错误。 (这很可能是打字错误,因此将其修复为
ctx.message.created_at
即可解决该问题。)
另一个问题是您使用 guild.icon
而不是 guild.icon_url
。
- 您需要使用 url 的原因是嵌入的消息无法处理图像。它需要 urls 来代替图像。
因此,解决这两个问题会使您的代码可执行:
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)
参考文献: