簡體   English   中英

獲取公會和會員圖標 discord.py

[英]Get Guild And Member Icon discord.py

所以我一直在嘗試制作一個serverinfo命令,但它總是給我一個錯誤。 我的代碼:

@bot.command(name='ServerInfo', description='Shows Server Info')
async def serverinfo(ctx):
  member = len(ctx.guild.members)
  Roles = len(ctx.guild.roles)
  embed = nextcord.Embed(title='**Information:**')
  embed.add_field(name='Name:', value=ctx.guild.name, inline=False)
  embed.add_field(name='ID:', value=ctx.guild.id, inline=False)
  embed.add_field(name='Owner:', value=ctx.guild.owner_id, inline=False)
  embed.add_field(name='Created At:', value=ctx.guild.created_at.strftime('Day: %d/%m/%Y Hour: %H:%M:%S %p'), inline=False)
  embed.add_field(name='Region:', value=ctx.guild.region, inline=False)
  embed.add_field(name='Total Members:', value=f'`{member}`', inline=False)
  embed.add_field(name=f'Total Roles:', value=f'`{Roles}`', inline=False)
  embed.set_thumbnail(url=ctx.guild.icon_url)
  embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
  embed.timestamp = datetime.datetime.utcnow()
  await ctx.send(embed=embed)

這是錯誤:

    raise CommandInvokeError(exc) from exc
nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Guild' object has no attribute 'icon_url'

同樣的事情發生在ctx.author.avatar_url 有人可以幫忙嗎? 謝謝!

如果您使用的是新的 discord.py 2.0 alpha 或任何新的分支, icon_url已更改為icon.url並且avatar_url現在為avatar.url

所以:

embed.set_thumbnail(url=ctx.guild.icon.url)
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar.url)

以下是一些更多重大變化的概述: https://gist.github.com/apple502j/f75b4f24652f04de85c7084ffd73ec58

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM