【问题标题】:Discord.py Splitting Emojis from Channel NamesDiscord.py 从频道名称中拆分表情符号
【发布时间】:2020-11-16 18:16:15
【问题描述】:

尝试创建一个类别中的频道列表,然后拆分频道名称和表情符号。然后从中发送嵌入。

问题在于,有时领域名称类似于#realm-name-emoji:

我使用- 来拆分名称,但在这种情况下我不能这样做,所以有没有办法检查表情符号是否是实际的表情符号?然后使用相同的表情符号,为机器人发送的嵌入添加一个反应。

我在这里用评论标记了这些问题。拆分表情符号和域名是否有更好的选择?

到目前为止,我有这个:

@commands.command()
    async def checkin(self, ctx):
      if ctx.guild.id != "guild id":
        return
      else:
        category = discord.utils.get(ctx.guild.categories, id="my ID here")
        checkinem = discord.Embed(title='Realms Channels')
        
        for channel in category.channels:
          realm, emoji = channel.name.split('-') #issue here
          checkinem.add_field(name=realm, value=emoji, inline=False)
        checkinmsg = await ctx.send(embed=checkinem)

        for channel in category.channels: 
          realm, emoji = channel.name.split('-') #issue here
          await checkinmsg.add_reaction(emoji=emoji)

任何帮助都会很棒!谢谢!

【问题讨论】:

  • 您可以尝试使用unicodedata.lookup(str),但对于某些像:white_check_mark: 这样的表情符号将不起作用

标签: python discord.py


【解决方案1】:

根据您的问题判断,您有两个可能的频道名称:

  • #realm-emoji
  • #realm-name-emoji

在这两种情况下,领域是第一个元素,表情符号是最后一个元素,因此,您可以检查拆分的频道名称长度:

channel = channel.split('-')
if len(channel) == 2: # #real-emoji
    realm, emoji = channel
else: # #realm-name-emoji  
    realm, emoji = channel[0], channel[-1]

【讨论】:

    猜你喜欢
    • 2021-07-05
    • 2019-03-25
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多