#Channel Cache Not Updating
1 messages · Page 1 of 1 (latest)
Yeah, got 'channel_id: Value "[object Object]" is not snowflake.' But at least its something new to hunt down.
Its a mess since I'm still playing around/testing, but here:
async execute(interaction, client) {
interaction.guild.channels.cache.clear();
// console.log(await interaction.options.data);
// console.log(await interaction);
let userId = await interaction.user.id;
let Guild = client.guilds.cache.get(guildId);
let Member = Guild.members.cache.get(userId);
console.log('========');
console.log('========');
console.log('channels for Member');
let test = await Member.guild.channels.fetch({ force: true });
console.log(test);
let filteredChannels = test.filter(
(channel) => channel.type === 'GUILD_VOICE'
);
filteredChannels.map((channel) => {
console.log(`CHANNEL ${channel.name}`);
console.log(channel.members);
});
await interaction.user.id?
Not sure what you're awaiting there lol
Also
you tried to fetch a channel with no ID
guild.channels.fetch('ID', { force: true })
If I remove the {force:true} it returns all channels on the guild.
Tho you really shouldn't have to force it as the cache should be accurate, but it's your code so 🤷♂️
I've spent a day on this. I've gone through the docs. Maybe I'm missing something obvious, but I'm literally frustrated beyond belief.
Send the code again
Specifically the area you fetch the channel
That code is messy, cause I'm just trying to find something that works. But it gets all the guilds, gets all channels and then I filter to the voice channels and then look at the members. That /works/ except when I leave/change a channel it doesn't update.
let test = await Member.guild.channels.fetch({ force: true });
let filteredChannels = test.filter(
(channel) => channel.type === 'GUILD_VOICE'
);
filteredChannels.map((channel) => {
console.log(`CHANNEL ${channel.name}`);
console.log(channel.members);
});
That gets all channels, then I filter for voice, then I map to see which channel has the member.
mhm
I'm down to do it another way. I don't care how I get it. I just want to know A) if the user is in a voice channel and B) which channel that is.
So remind me what the issues of using the cache were
not updating?
Also you shouldn't have to force fetch all the channels
Here's what's happening:
- I have a user in a channel (let's say voice 1)
- I start the bot
- I run the command and get the list of channels, filter it, map it and the user shows in the correct channel
- I leave the bot running
- I change the user to 'voice 2'
- I run the command again, and the user is still showing in 'voice 1'
I don't want to force the data per se, but I just need the accurate info on which voice channel the user is in.
Show me the code you tried with the cache
I tried this
let voiceChannels2 = await interaction.guild.channels.cache;
let filteredChannels2 = voiceChannels2.filter(
(channel) => channel.type === 'GUILD_VOICE'
);
filteredChannels2.map((channel) => {
console.log(`CHANNEL ${channel.name}`);
console.log(channel.members);
});
But even if I take the code I shared earlier and swap the .fetch for .cache I still have the issue.
Probably because I've gone off the deep end.
soo
I'm 99% sure I did it without the await but let me test real quick
Of course not. I didn't even catch that.
That throws a throw new RangeError('BITFIELD_INVALID', bit); which I suspect is a permissions error.
Yeah
one sec
@ivory cobalt add GUILD_VOICE_STATES
then try using member.voice.channel
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.GUILD_VOICE_STATES,
],
As soon as I have the GUILD_VOICE_STATES line I got the new error.
Yes
Do I need anything else checked in the top part?
No error:
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.GUILD_VOICE_STATES,
],
});
And its coming from line 7 of index.js, which is what I quoted.
at Object.<anonymous> (F:\websites\projects\heroesbot\index.js:7:16)
No
Yeah, just caught that myself.
I did need applications.commands from that screen cap. (I had booted the bot and readded it without that checked and couldn't readd commands).
But after all of that, got my commands readded and its working now.
So it was the intent that I missed. The easiest part.
Thank you for your help. Definitely appreciate it.