我正在尝试设置我的第一个Discord机器人,以便能够用其他字母替换某些字母,但是我对使用javascript编码非常陌生。
function debunkCommand(arguments, recievedMessage) {
if (arguments.length > 0) {
function strReplace(){
var myStr = argument;
var newStr = myStr.replace(/l/gi, "w");
var newStr = myStr.replace(/r/gi, "w");
receivedMessage.channel.send(newStr)
}
} else {
receivedMessage.channel.send("that's impossible to debunk")
}
}
期望能够编写“!debunk hello”并让机器人发回一条消息,说“ hewwo”
答案 0 :(得分:0)
function debunkCommand(args, receivedMessage) {
if (args.length) {
/*
arguments is an array of strings, doing 'arguments.join(" ")' will join these strings into one
/[lr]+/gi will match any instances of 'l' or 'r'
it's also a good idea to rename your "arguments" parameter to "args", since "arguments" is already a standart js object
*/
receivedMessage.channel.send(args.join(" ").replace(/[lr]+/gi, "w"));
} else {
receivedMessage.channel.send("that's impossible to debunk");
};
};