简体   繁体   中英

Discord bot is not executing commands (discord.js v11.5.1)

Last night I rewrote my index.js and now it's not executing commands anymore. I have tried updating & downgrading my discord.js version but nothing has changed, I tried using my old index.js and for some reason that didn't work either.

Here is my 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))
});

Thanks!

You have a check that says if(.message.author;bot) return; which returns if the author is NOT a bot, so you have to remove the ! from that check

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM