Discord.js 如何使用channelid获取特定的discord bot频道?
使用Discord.js 如何使用channelid获取特定的discord bot频道?,discord.js,Discord.js,使用bot.channels.get(channelid)时,我的bot返回undefined 以下是我的代码示例: 文件./DatStore/guiddat/41680932051301713.dat包含: 以下是输出: 如果找到通道,则应在输出中记录“通道已找到” 我应该更改什么以使其返回频道?频道id键是一个字符串,您必须将其作为字符串包含在数组中 let c1=bot.channels.get(42408550336161417200);//将产生未定义的 设c2=bot.channel
bot.channels.get(channelid)
时,我的bot返回undefined
以下是我的代码示例:
文件./DatStore/guiddat/41680932051301713.dat包含:
以下是输出:
如果找到通道,则应在输出中记录“通道已找到”
我应该更改什么以使其返回频道?频道id键是一个字符串,您必须将其作为字符串包含在数组中
let c1=bot.channels.get(42408550336161417200);//将产生未定义的
设c2=bot.channels.get('42408550361417200');//将生成通道对象(如果可用)
频道不可用,因为我使用了错误的id:
我在服务器设置命令中以int格式保存了id,而不是字符串,parseInt()打破了确切的数字
谢谢你试着帮助我
//this is executed in a guild with id 416809320513011713
const Discordjs = require("discord.js");
const bot = new Discordjs.Client();
const auth = require('./auth.json');
const FileSys = require("fs");
bot.on('messageDelete', async function (message) {
console.log('message deleted')
let currentguildsettings = JSON.parse(FileSys.readFileSync('./DatStore/GuildDat/' + message.guild.id + '.dat', 'UTF8'));
if (currentguildsettings[0] == 1) {
if (currentguildsettings[1] != 0) {
let channelid = currentguildsettings[1].toString()
let channel = bot.channels.get(channelid);
console.log('settings on true, channelid ' + channelid)
if (channel) {
console.log('channel found')
}
}
}
}
bot.login(auth.token)
[1,424085503361417200,0]
message deleted
settings on true, channelid 424085503361417200
if (logchannelaction == 'set') {
if (currentguildsettings[1] == message.channel.id) return message.reply("logchannel was already set to this channel");
currentguildsettings[1] = parseInt(message.channel.id);
message.reply("logchannel has set to #" + message.channel.name);
if (currentguildsettings[0] == 0) {
currentguildsettings[0] = 1
message.reply("logchannel has automatically enabled");
}
FileSys.writeFileSync(guilddatpath, JSON.stringify(currentguildsettings));
return
}