我如何从准备好的活动中获得特定的公会id ?



所以我要做的是让这个机器人在多个服务器上工作,所以我想获得一个特定的公会id一样使用message.guild.id,但由于没有消息定义或声明我怎么能得到它,任何想法?

谢谢代码:

const db = require(`quick.db`)
let cid;
const { prefix } = config
client.on('ready', async () => {

console.log(`${client.user.tag} is online`);
console.log(`${client.guilds.cache.size} Servers`);
console.log(`Server Names:n[ ${client.guilds.cache.map(g => g.name).join(", n ")} ]`);

loadCommands(client)
cid = db.get(`${message.guild.id}_channel_`) // this line - 14 


cron.schedule('*/10 * * * * *', () => {
const zkrRandom = zkrList[Math.floor(Math.random() * zkrList.length)]
const zkrEmbed = new Discord.MessageEmbed()

.setDescription(zkrRandom)
.setAuthor('xx', logo)
.setColor('#447a88')


client.channels.cache.get(cid).send(zkrEmbed);
})
client.on("message", async message => {


if (message.author.bot) {
return
}
try {if (!message.member.hasPermission('ADMINISTRATOR') && message.content.startsWith('!s')) return message.reply('you do not have the required permission') } catch (err) {console.log(err)}
if (!message.content.startsWith(prefix)) return;

const args = message.content.slice(prefix.length).trim().split(/ +/g)
const cmd = args[0]
if (cmd === "s") {
let c_id = args[1]
if (!c_id) return message.reply("you need to mention the text channel")
c_id = c_id.replace(/[<#>]/g, '')
const channelObject = message.guild.channels.cache.get(c_id);


if (client.channels.cache.get(c_id) === client.channels.cache.get(cid)) return message.reply(`we already sending to the mentioned text channel`);
if (client.channels.cache.get(c_id)) {


await db.set(`${message.guild.id}_channel_`, c_id); //Set in the database
console.log(db.set(`${message.guild.id}_channel_`))
message.reply(`sending to ${message.guild.channels.cache.get(c_id)}`);
cid = db.get(`${message.guild.id}_channel_`)

const zkrRandom = zkrList[Math.floor(Math.random() * zkrList.length)]
const zkrEmbed = new Discord.MessageEmbed()

.setDescription(zkrRandom)
.setAuthor('xx', logo)
.setColor('#447a88')


client.channels.cache.get(cid).send(zkrEmbed);

} else {
return message.reply("Error")
}

}
})
})


client.login(config.token)

我得到的错误

cid = db.get(`${message.guild.id}_channel_`)
^
ReferenceError: message is not defined

行业名称和id这些数据存储在guilds.cache下。因此,以同样的方式,你得到所有的公会名称,你的机器人已加入。你可以简单地将name更改为id,以获得bot加入的所有公会id。这将以数组形式返回。

console.log(client.guilds.cache.map(guild => guild.id)) // ['1234567890', '0987654321']

最新更新