为了账号安全,请及时绑定邮箱和手机立即绑定

如何制作将channelID存储在数据库中的命令?

如何制作将channelID存储在数据库中的命令?

守候你守候我 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,它将设置为作者等。


希望这在某种程度上有所帮助。


查看完整回答
反对 回复 2021-12-12
  • 1 回答
  • 0 关注
  • 235 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号