【问题标题】:How do i send the role name?如何发送角色名称?
【发布时间】:2020-11-12 15:22:15
【问题描述】:
    if before.roles != after.roles:
        with open("log.json", 'r') as f:
             ac = json.load(f)
        for key in ac:
          if int(key) == after.guild.id:
       # for key in ac:
              channel = client.get_channel(ac[key])
              #embed = discord.Embed(
              #    colour = COLOR
              #)
              #embed.set_author(name=NAME)
              #embed.set_thumbnail(url=PFP)
              #embed.add_field(name="Old nickname", value=f"{before.display_name}", inline=True)
              #embed.add_field(name="New nickname", value=f"{after.display_name}", inline=True)
              await channel.send(f"{before.roles}, {after.roles}")
              #await channel.send(embed=embed)

我只是不断收到this

如何让它显示被删除/添加的角色而没有所有其他垃圾?

【问题讨论】:

  • 你必须解析“垃圾”并提取你想要的。
  • 我是pythong的新手,什么意思?

标签: python-3.x discord bots discord.py


【解决方案1】:

如果您只想打印所有角色名称,则可以使用 join 函数并将角色作为可迭代对象传递。

例如,下面将发送角色之前和之后,角色之间用逗号连接:

before_roles = ",".join([role.name for role in before.roles])
after_roles = ",".join([role.name for role in after.roles])
await channel.send(f"{before_roles}, {after_roles}")

【讨论】:

  • 谢谢,但我如何只打印添加/删除的角色?
猜你喜欢
  • 2021-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-11
  • 2022-01-15
  • 2012-07-29
  • 2021-11-02
相关资源
最近更新 更多