我正在制作一个反应机器人,我目前正在制作添加表情符号命令。该命令需要消息id,它将为用户提供角色,以及它将显示的表情符号。但是我不知道怎么把表情符号变成一种身份?我不知道如何将提到的角色转换为id,有人能帮我吗?
let ARGmsgId = args[0];
let ARGemoji = args[1]; // USER IS GOING TO ENTER IN AN EMOJI - I WANT TO TURN IT INTO A SORT OF EMOJI ID THAT I CAN STORE IN THE DATABASE
let ARGrole = args[2]; //USER IS GOING TO MENTION A ROLE - I WANT TO TURN IT INTO A ROLE ID THAT I CAN STORE IN THE DATABASE这些是我目前的观点
发布于 2020-11-27 03:58:32
自定义表情符号将以<a:name:id>格式进行解析(如果未定义,则使用a )。unicode表情符号将被解析为:name:。无论哪种方式,您都可以使用String#match()来提取ID。
const emoji = args[1].match(/<a?:(.+):\d{17,18}>|:(.+):/)[1];
// regex breakdown:
// a? - question mark after any character means optional
// () - this will capture the name for later recognition
// .+ - one or more of any character (the name)
// \d{17,18} - the 17-18 digit ID
// | - or operator- either use the format for the custom emoji or the unicode要获得提到的角色,请使用MessageMentions#roles和Collection#first
const role = message.mentions.roles.first();https://stackoverflow.com/questions/65027295
复制相似问题