【发布时间】:2021-04-01 15:36:23
【问题描述】:
我一直收到一个
“TypeError: 无法读取未定义的属性‘split’”
为我的不和谐机器人运行-mute 命令时。我正在关注这个tutorial:
导致错误的行看起来与他的相同。这是我的代码:
const {
GuildMember
} = require("discord.js")
const BotVersion = require('../package.json').version;
const Discord = require("discord.js");
var botdev = require('../data.json').botdev;
const redis = require('../redis.js')
module.exports = {
name: 'mute',
description: "mute",
execute(async, message, args) {
const { content, channel, mentions } = message
const split = content.trim().split(' ')
const syntax = '-mute <@member> <duration as a number> <m, h, d, or life>';
if (split.length !== 4) {
channel.send('Insufficient parameters :no_entry_sign:\n**Syntax**: ' + syntax)
return;
}
const duration = split[2]
const durationType = split[3]
if (isNaN(duration)) {
channel.send('Please provide a number for the duration\n**Syntax**: ' + syntax)
return;
}
const durations = {
m: 60,
h: 60 * 60,
d: 60 * 60 * 24,
life: -1
}
if (!durations[durationType]) {
channel.send('Please provide a valid duration type\n**Syntax**: ' + syntax)
return;
}
const seconds = duration * durations[durationType];
console.log('MENTIONS:', mentions)
const redisClient = await (redis)
try {
} finally {
redisClient.quit()
}
}
}
【问题讨论】:
-
嗨,堆栈跟踪是否告诉您错误发生在哪里?
-
第 15:31 行,忘记包含了,抱歉。
-
你能在函数的开头添加
console.log(message)和console.log(message.content)吗? -
@Aplet123 ['静音', '', '1', 'm' ] 未定义
-
你的函数应该是
async execute(message, args)或execute(message, args),而不是execute(async, message, args)。
标签: discord.js