所以這是我的代碼:當一個變量替換字符,我得到這個錯誤
exports.run = (client, message, args, Discord) => {
args = args.replace(/&/g, "").trim() || "+";
但我得到這個錯誤
args.replace is not a function
誰能幫助?
所以這是我的代碼:當一個變量替換字符,我得到這個錯誤
exports.run = (client, message, args, Discord) => {
args = args.replace(/&/g, "").trim() || "+";
但我得到這個錯誤
args.replace is not a function
誰能幫助?
參數最有可能不是一個字符串,而是一個數組。您可以使用for循環遍歷數組,並在那裏進行替換。
for (var i = 0; i < args.length; i++) {
args[i] = args[i].replace(/&/g, "").trim() || "+";
}
可能args不是一個字符串。 –
檢查參數的類型,可能它不是字符串對象'console.log(typeof(args));' 另外,檢查'args'是否是字符串,然後它是空的? –
@OmSao這也沒有工作:'''console.log(typeOf(args)); ^ ReferenceError:typeOf is not defined''' – Anidox