javascript - 更改命令前缀后,旧的仍然可以使用
问题描述
我有一个命令来更改我的机器人的前缀。该命令有效,但更改前缀后,仍可以使用之前的前缀。但我希望在更改后只能使用新的前缀。
到目前为止,这是我的代码:
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 ☑",
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"
}
如何确保更改后只能使用新前缀?
解决方案
我不熟悉quickDB
,但我认为您的某些逻辑是错误的。
假设您使用的语法是正确的,并且数据库更新,请确保在您的命令处理程序中您使用的是新前缀,而不是默认前缀。您应该这样做,以便在处理您发送的每条消息(即在您的bot.on("message")
事件中)期间加载前缀。
我建议不要删除数据库中的整个表或行,而只是更改它们,这可能是你的问题,但我不熟悉你的代码,或者quickDB
.
推荐阅读
- jmeter - JMeter BeanShell PreProcessor 修改请求
- google-cloud-sql - 连接上的 IP 但仍无法通过 Workbench 访问
- python - 将 httpie post 请求转换为 python 请求库
- android - queryPurchases 为空,但用户在正确的帐户下,并且在尝试购买时说他们已经拥有该项目
- html - 如何打破表格TD元素中的长单词?
- javascript - 通过 javascript 上传票证上传到 Azure Blob
- javascript - 限制 Firebase 与 Electron 应用程序通信
- java - 比较 Flink 中的 2 个数据流以检索丢失的数据
- php - 在 WordPress 网站上为人们创建私人页面
- php - Indeed 授权 API 返回无效授权