昨晚我重写了index.js,现在它不再执行命令了。我曾尝试过更新和降级discord.js版本,但没有任何改变,我尝试使用旧的index.js,由于某种原因,该版本也无法正常工作。
这是我的index.js:
const {Client} = require('discord.js')
const bot = new Client()
const prefix = "%";
const owners = [''];
bot.login('')
bot.on('ready', (msg) => {
console.log(`${bot.user.tag}: [${new Date(Date.now()).toUTCString()}]`);
});
bot.on("message", async (message) => {
if(!message.author.bot) return;
if(!message.content.startsWith(prefix)) return;
let args = message.content.slice(prefix.length).trim().split(/ +/g);
let path = `./commands/${args.shift().toLowerCase()}.js`;
if(!require("fs").existsSync(path)) return;
const command = require(path);
if(!command.ownersOnly) command.run(bot, message, args);
else {return message.channel.send('You are not allowed to do that!')}
});
bot.on('message', (msg) => {
if(msg.content === "prefix") {
msg.reply("Prefix: " + prefix)
}
});
bot.on("messageDelete", (m) => {
if(m.author.bot) return
const path = __dirname + "/snipe.json"
let snipeFile = require(path)
snipeFile[m.channel.id] = [m.author.id, m.content, m.attachments.first() ? m.attachments.first().proxyURL : undefined]
require("fs").writeFileSync(path, JSON.stringify(snipeFile, null, 2))
});
谢谢!
答案 0 :(得分:1)
您有一张写着if(!message.author.bot) return;
的支票,如果作者不是机器人,它会返回,因此您必须从该支票中删除!