守候你守候我
2021-12-12 10:50:37
我如何制作一個命令,將 channelID 存儲在數據庫中,也通過數據庫,有點像我機器上的一個大文本文件,它有一個服務器 id,然后是一個通道 id。我該怎么辦?我正在使用:discord.js sqlite3 sequelize我認為它會如何:用戶:?setlog #channelmentionhere Bot:將新的全部內容放入文本文件或其他內容中我做了大量的研究,我無法理解其中的大部分內容,如果我確實理解了它,我就會遇到麻煩。我的機器人代碼:client.on('message', message => { if (!message.content.startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).split(/ +/); const commandName = args.shift().toLowerCase(); const user = message.mentions.users.first(); const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); if (!command) return; if (command.guildOnly && message.channel.type !== 'text') { return message.reply('I can\'t execute that command inside DMs!'); } if (command.args && !args.length) { let reply = `You didn't provide any arguments, ${message.author}!`; if (command.usage) { reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``; } return message.channel.send(reply); } if (!cooldowns.has(command.name)) { cooldowns.set(command.name, new Discord.Collection()); } const now = Date.now(); const timestamps = cooldowns.get(command.name); const cooldownAmount = (command.cooldown || 3) * 1000;
1 回答

一只斗牛犬
TA貢獻1784條經驗 獲得超2個贊
我會推薦 Quick.db ( npm i quick.db) 這個數據庫持久存儲(不會在機器人重啟時擦除)
在以下代碼片段中,我使用的是 quick.db,但使用 Json 文件應該不會太難。
設置每個公會的頻道ID:(你不必使用會員,但我習慣這樣做)
let member = message.guild.member(message.member);
db.set(`${member.guild.id}-modlogs`, message.mentions.channels.first().id);
在其他命令中抓取數據庫然后發送通道消息:
let dbchannelID = db.get(`${member.guild.id}-modlogs`)
let msgchannel = member.guild.channels.get(dbchannelID);
msgchannel.send("Blah Blah")
在解釋db.set部分:
所以db.set在設置數據庫,并在此數據庫會modlogs。db.set&之間的文本modlogs是您想要將其設置為的方式,在這里它是每個公會的設置。您可以將其更改為message.author.id,它將設置為作者等。
希望這在某種程度上有所幫助。
添加回答
舉報
0/150
提交
取消