好吧,我正在尝试从这个 <: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)
}
答案 0 :(得分:-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
}
}
我知道这是一段糟糕的代码。但它有效