首页 > 解决方案 > 更改命令前缀后,旧的仍然可以使用

问题描述

我有一个命令来更改我的机器人的前缀。该命令有效,但更改前缀后,仍可以使用之前的前缀。但我希望在更改后只能使用新的前缀。

到目前为止,这是我的代码:

const db = require("quick.db")
const { default_prefix } = require("../../configs/config.json")
const config = require('../../configs/config.json')

module.exports = {
config: {
  name: "newprefix",
  category: "moderation",
  usage: "prefix <new-prefix>",
  description: "Change the guild prefix",
  aliases: ["npx", "spx"],
},
  run: async (client, message, args) => {
    //PERMISSION
    if(!message.member.hasPermission("ADMINISTRATOR")) {
      return message.channel.send({
        embed: {
          title: "You do not have permission [ADMINISTRATOR] to perform this act",
          color: config.embedcolor
        }
      })
    }
    
    if(!args[0]) {
      return message.channel.send({
        embed: {
          title: "You need to enter the prefix to want to set",
          color: config.embedcolor
        }
      })
    } 
    
    if(args[1]) {
      return message.channel.send({
        embed: {
          title: "You can not set prefix a double argument",
          color: config.embedcolor
        }
      })
    }
    
    if(args[0].length > 3) {
      return message.channel.send({
        embed: {
          title: "You can not send prefix more than 3 characters",
          color: config.embedcolor
        }
      })
    }
    
    if(args.join("") === default_prefix) {
      db.delete(`prefix_${message.guild.id}`)
     return await message.channel.send({
      embed: {
        title: "Prefix resetted ☑&quot;,
        color: config.embedcolor
      }
    })
    }
    
    db.set(`prefix_${message.guild.id}`, args[0])
  await message.channel.send({
    embed: {
      title: `Seted Bot Prefix to ${args[0]}`,
      color: config.embedcolor
    }
  })
    
  }
} 

这是我的配置:

    {       
        "prefix": ".",
        "embedcolor": "#1DCAD3", 
        "dev": "582495058352406528",   
        "token": "My token is here",
        "hostedBy": "true"            
    }

如何确保更改后只能使用新前缀?

标签: javascriptdiscord.js

解决方案


我不熟悉quickDB,但我认为您的某些逻辑是错误的。

假设您使用的语法是正确的,并且数据库更新,请确保在您的命令处理程序中您使用的是新前缀,而不是默认前缀。您应该这样做,以便在处理您发送的每条消息(即在您的bot.on("message")事件中)期间加载前缀。

我建议不要删除数据库中的整个表或行,而只是更改它们,这可能是你的问题,但我不熟悉你的代码,或者quickDB.


推荐阅读