我正在尝试使用命令处理程序为Discord机器人执行ping命令,但是当我尝试在Discord中运行命令时,出现以下错误:(我正在使用PM2运行我的机器人并对其进行记录)
TypeError:无法读取未定义的属性“发送”
我的命令的代码是:
module.exports.run = async (message) => {
message.channel.send('pinging...').then(m => {
var ping = m.createdTimestamp - message.createdTimestamp;
m.edit(ping + 'ms' + ', pong!');
});
};
module.exports.config = {
name: 'ping',
displayName: 'ping',
aliases: ['p'],
usage: 'ping',
description: 'gets your ping (i hope it\'ts high)',
accessableby: 'members',
type: 'utility'
};
我的index.js代码是:
const Discord = require('discord.js');
const client = new Discord.Client( {
disableEveryone: true
});
const { prefix, token } = require('./config.json');
client.on('ready', async () => {
console.log('bot is too ready for this.');
let botstatus = ['for bot.help', `at ${client.guilds.size} servers`]
client.user.setActivity(botstatus, {
type: 'WATCHING'
});
});
const fs = require('fs');
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
let pathCMD ='./commands/';
fs.readdir(pathCMD, (err, files) => {
if (err) return console.log(err);
let jsfiles = files.filter(f => f.split('.').pop() === 'js');
if (jsfiles.length < 1) return console.log('commands are nah');
else console.log(`loading ${jsfiles.length} commands man`);
jsfiles.forEach((f, i) => {
delete require.cache[require.resolve(pathCMD + f)];
var pull = require(pathCMD + f);
console.log(`man, i loaded ${f} (${i+1}/${jsfiles.length})`);
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
client.aliases.set(alias, pull.config.name);
});
});
});
client.on('message', async message => {
if (message.author.bot) return;
let messageArray = message.content.split(' ');
let cmd = messageArray[0].substring(prefix.length).toLowerCase();
let args = messageArray.slice(1);
if(!message.content.startsWith(prefix)) return;
else console.log(`[CMD] ${message.author.tag} used ${cmd}`);
let commandfile = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd));
if (commandfile) commandfile.run(client, message, args);
});
client.login(token);
我不知道这是否有帮助,但是我在Windows 10上使用Node版本13.7.0,NPM版本6.14.2和discord.js版本12.0.1。
答案 0 :(得分:0)
尝试从此更改ping命令文件
module.exports.run = async (message) => {
message.channel.send('pinging...').then(m => {
var ping = m.createdTimestamp - message.createdTimestamp;
m.edit(ping + 'ms' + ', pong!');
});
};
收件人:
module.exports.run = async (client, message, args) => {
message.channel.send('pinging...').then(m => {
var ping = m.createdTimestamp - message.createdTimestamp;
m.edit(ping + 'ms' + ', pong!');
});
};