我试图使用一个命令使用 lowdb 保存公会 ID 和通道 id,但是当我使用var server = client.guilds.get(message.guild.id).id;
时,我收到错误,说,无法读取未定义的属性"get"。我不知道为什么。
var server = client.guilds.get(message.guild.id).id;
var channel = client.guilds.get(message.channel.id).id;
db.get('posts')
.push({ id: server, title: channel})
.write();
有我制作的所有代码,我在代码开始时定义所有内容
const client = require('<there's path but I don't want to show it cuz there's my name>/my_bot.js');
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json')
const db = low(adapter)
如果您知道出了什么问题,请提供帮助
如果您使用的是 discord.js@v12,那么您应该记住,您应该通过.cache
属性才能使代码正常工作。您可以通过查看文档来自己检查Client.guilds
。
此外,你不需要从他们的ID中获取频道和公会,因为你已经将它们存储为消息属性。
以下是我会怎么做:
let server = message.guild.id, // ID of the guild the message was sent in
channel = message.channel.id // ID of the channel the message was sent in
公平地说,我无法解释为什么你会得到这个错误。
好的,所以你得到"get"不是一个函数,因为在v12中它必须是client.guilds.cache.get(whatever you wanna put here
(