#Channel Cache Not Updating

1 messages · Page 1 of 1 (latest)

ivory cobalt
#

Yeah, got 'channel_id: Value "[object Object]" is not snowflake.' But at least its something new to hunt down.

noble hornet
#

Wat

#

Send code

ivory cobalt
#

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);
    });
noble hornet
#

Not sure what you're awaiting there lol

#

Also

#

you tried to fetch a channel with no ID

#

guild.channels.fetch('ID', { force: true })

ivory cobalt
#

If I remove the {force:true} it returns all channels on the guild.

noble hornet
#

Tho you really shouldn't have to force it as the cache should be accurate, but it's your code so 🤷‍♂️

ivory cobalt
#

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.

noble hornet
#

Specifically the area you fetch the channel

ivory cobalt
#

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.

noble hornet
#

mhm

ivory cobalt
#

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.

noble hornet
#

So remind me what the issues of using the cache were

#

not updating?

#

Also you shouldn't have to force fetch all the channels

ivory cobalt
#

Here's what's happening:

  1. I have a user in a channel (let's say voice 1)
  2. I start the bot
  3. I run the command and get the list of channels, filter it, map it and the user shows in the correct channel
  4. I leave the bot running
  5. I change the user to 'voice 2'
  6. 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.

noble hornet
#

Show me the code you tried with the cache

ivory cobalt
#

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.

noble hornet
#

what

#

Why are you still awaiting it

#

await interaction.guild.channels.cache?

ivory cobalt
#

Probably because I've gone off the deep end.

noble hornet
#

soo

ivory cobalt
#

I'm 99% sure I did it without the await but let me test real quick

noble hornet
#

member.voice.channel is failing

#

due to not updating

ivory cobalt
#

Yes.

#

And I took out the await and no change.

noble hornet
#

Oh

#

By the way

#

do you have the intent

#

for voice states

#

enabled

ivory cobalt
#

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.

noble hornet
#

Yeah

#

one sec

#

@ivory cobalt add GUILD_VOICE_STATES

#

then try using member.voice.channel

ivory cobalt
#
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.

noble hornet
#

Wat error

#

The invalid bitfield?

ivory cobalt
#

Yes

noble hornet
#

Huh

#

That's really weird

ivory cobalt
#

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)

noble hornet
#

Oh

#

Intents**.FLAGS**.GUILD_VOICE_STATES

#

@ivory cobalt

ivory cobalt
#

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.