【问题标题】:get emoji name from <:Emoji_name:ID>从 <:Emoji_name:ID> 获取表情符号名称
【发布时间】:2021-07-07 01:26:02
【问题描述】:

好的,所以我正在尝试从此 <:emoji_name:id> 获取表情符号的名称。但是 .slice() 不起作用,我在这里的知识已经到了尽头,所以嗯,是的,如果有人能帮忙就好了!这是我的命令代码。 ????

else if (command === 'emoji') {
  let findEmoji = msg.content.match(/<a:.+?:\d+>|<:.+?:\d+>/g)
  if (!findEmoji) return msg.reply("Please mention an emoji!")
  oneEmoji = findEmoji.slice(0, 1)
  emojiId = msg.content.match(/\d+/g)
  oneEmojiId = emojiId.slice(0, 1)
  embed = new Discord.MessageEmbed()
    .setTitle("Emoji information")
    .addFields({
      name: 'Emoji name:',
      value: "coming soon",
      inline: true
    }, {
      name: 'Emoji for bots:',
      value: "`" + oneEmoji + "`",
      inline: true
    }, {
      name: 'Emoji id:',
      value: oneEmojiId,
      inline: true
    }, {
      name: 'Emoji link:',
      value: `https://cdn.discordapp.com/emojis/${oneEmojiId}.png?v=1`,
      inline: true
    }, )
    .setThumbnail(`https://cdn.discordapp.com/emojis/${oneEmojiId}.png?v=1`)
  msg.channel.send(embed)
}

【问题讨论】:

    标签: javascript discord.js emoji


    【解决方案1】:

    试试这个:

    let args = message.content.split(" ");
    let command = args[0].slice(1).toLowerCase();
    /*
    Let's guess you have some if .... else
    */
    else if (command === "emoji"){
        if(args[1].match(/<a:.+?:\d+>|<:.+?:\d+>/g)){  //The OP's regex
            let emoji;
            if(args[1] === "a"){
                emoji = args[1].slice(3, (args[1].length-1) ); //animated
            }else{
                emoji = args[1].slice(2, (args[1].length-1) ); //Non animated
            }
            emojiID = emoji.split(":")[1];
            emojiName = emoji.split(":")[0];
            // Put the embed
        }
    }
    

    我知道这是一段糟糕的代码。但它有效

    【讨论】:

    • 看到自己的代码让我感到畏缩。如果你能做得更好,请随时编辑
    • 是的,它没有工作它只是删除了整个名称而不是 :ty 尝试 tho lol
    【解决方案2】:
    let args = msg.content.slice(PREFIX.length).trim().split(/ +/); //be sure to specify the prefix or just get rid of that part
    let namever1 = args[1].replace('<','')
    let namever2 = namever1.replace('>','')
    let namever3 = namever2.split(':')
    let name = namever3[1] //Emoji name
    let id = namever3[2] //emoji id
    //if you want the link: "https://cdn.discordapp.com/emojis/"+id+".png?/v=1"
    //also note theres a difference between animated and none animated (aniamted ones require "let namever1 = ForBots.replace('<a','')" also the link has to change to "https://cdn.discordapp.com/emojis/"+id+".gif?/v=1")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 2021-07-24
      • 2020-11-11
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多