javascript - Discord bot 不执行命令 (discord.js v11.5.1)
问题描述
昨晚我重写了我的 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))
});
谢谢!
解决方案
您有一张支票,上面写着if(!message.author.bot) return;
如果作者不是机器人,则返回,因此您必须!
从该支票中删除
推荐阅读
- r - 在不全部包含相同级别的列上分解为整数
- python - 熊猫自定义功能,以查找是否是第一个,第二个等星期一,星期二等 - 欢迎所有建议
- c# - 将文件移动到另一个文件夹但被视为丢失
- java - 为什么我的 gif 只有在我单击 ImageView 时才会加载?
- typescript - 在 TypeScript 中,推断动态参数是动态函数的参数
- discord - Discord.py 命令上的命令错误消息
- azure-active-directory - 如何使用 Graph API 通过 id 或 userPrincipalName 获取用户对象?
- typescript - 用于对象的名为 arg 的打字稿
- ffmpeg - 如何使用ffmpeg在视频的最后5秒排除水印覆盖
- pine-script - 如何更改满足我在 Pine Script 中的蜡烛标准/定义的蜡烛的蜡烛颜色?