if(command === 'bigletters')
{
String.prototype.replaceAll = function(str1, str2, ignore)
{
return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignore?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);
let str = args.join(" ")
let olda = "a"
let oldb = "b"
let oldc = "c"
let oldd = "d"
let olde = "e"
let oldf = "f"
let oldg = "g"
let oldh = "h"
let oldi = "i"
let oldj = "j"
let oldk = "k"
let oldl = "l"
let oldm = "m"
let oldn = "n"
let oldo = "o"
let oldp = "p"
let oldq = "q"
let oldr = "r"
let olds = "s"
let oldt = "t"
let oldu = "u"
let oldv = "v"
let oldw = "w"
let oldx = "x"
let oldy = "y"
let oldz = "z"
str.replaceAll(olda, ":regional_indicator_a:");
str.replaceAll(oldb, ":regional_indicator_b:");
str.replaceAll(oldc, ":regional_indicator_c:");
str.replaceAll(oldd, ":regional_indicator_d:");
str.replaceAll(olde, ":regional_indicator_e:");
str.replaceAll(oldf, ":regional_indicator_f:");
str.replaceAll(oldg, ":regional_indicator_g:");
str.replaceAll(oldh, ":regional_indicator_h:");
str.replaceAll(regi, ":regional_indicator_i:");
str.replaceAll(oldj, ":regional_indicator_j:");
str.replaceAll(oldk, ":regional_indicator_k:");
str.replaceAll(oldl, ":regional_indicator_l:");
str.replaceAll(oldm, ":regional_indicator_m:");
str.replaceAll(oldn, ":regional_indicator_n:");
str.replaceAll(oldo, ":regional_indicator_o:");
str.replaceAll(oldp, ":regional_indicator_p:");
str.replaceAll(oldq, ":regional_indicator_q:");
str.replaceAll(oldr, ":regional_indicator_r:");
str.replaceAll(olds, ":regional_indicator_s:");
str.replaceAll(oldt, ":regional_indicator_t:");
str.replaceAll(oldu, ":regional_indicator_u:");
str.replaceAll(oldv, ":regional_indicator_v:");
str.replaceAll(oldw, ":regional_indicator_w:");
str.replaceAll(oldx, ":regional_indicator_x:");
str.replaceAll(oldy, ":regional_indicator_y:");
str.replaceAll(oldz, ":regional_indicator_z:");
msg.channel.sendMessage(str + " '''" + str + "'''")
}`
这是我试图为一个不和谐机器人执行的代码,我有这样的话,当有人说--bigletters然后他们想要的消息,exe -bigletter我喜欢馅饼 我希望它用表情符号替换每个字母,以使其成为大字母&#39;正如它所述,但它不起作用,它输出的是&#39; a b c d&#39;或者&#39; abcd&#39;当我做的时候 - 大小写一个b c d或abcd
有人可以帮帮我吗?
答案 0 :(得分:0)
只是......不要这样做:
if (command === 'bigletters') {
const str = args.join(' ');
const replaced = str.replace(/[a-z]/g, ':regional_indicator_$&:');
msg.channel.sendMessage(str + " '''" + replaced + "'''")
}
String.prototype.replace
采用正则表达式。如果正则表达式具有g
标志,则它将替换字符串中的所有匹配项。 /[a-z]/
将小写“a”与“z”匹配。替换中的$&
是匹配的文本。