Can't find user's voice channel!

When using member.voice.channel it returns null and I can't understand why.
export async function execute(interaction: ChatInputCommandInteraction){

let member = await interaction.guild!.members.fetch(interaction.user.id);
let channel = member.voice.channel;
// null
export async function execute(interaction: ChatInputCommandInteraction){

let member = await interaction.guild!.members.fetch(interaction.user.id);
let channel = member.voice.channel;
// null
I have the GuildVoiceStates intent and I am on a voice channel when doing the command. discord.js version: 14.13.0 node version: 18.18.0
8 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
bernardo
bernardoOP15mo ago
Logging member.voice returns this:
VoiceState {
guild: <ref *1> Guild {
id: '[GUILD SNOWFLAKE]',
name: undefined,
icon: undefined,
features: undefined,
commands: GuildApplicationCommandManager {
permissions: [ApplicationCommandPermissionsManager],
guild: [Circular *1]
},
members: GuildMemberManager { guild: [Circular *1] },
channels: GuildChannelManager { guild: [Circular *1] },
bans: GuildBanManager { guild: [Circular *1] },
roles: RoleManager { guild: [Circular *1] },
presences: PresenceManager {},
voiceStates: VoiceStateManager { guild: [Circular *1] },
stageInstances: StageInstanceManager { guild: [Circular *1] },
invites: GuildInviteManager { guild: [Circular *1] },
scheduledEvents: GuildScheduledEventManager { guild: [Circular *1] },
autoModerationRules: AutoModerationRuleManager { guild: [Circular *1] },
available: false,
shardId: 0
},
id: '[USER SNOWFLAKE]',
serverDeaf: null,
serverMute: null,
selfDeaf: null,
selfMute: null,
selfVideo: null,
sessionId: null,
streaming: null,
channelId: null,
suppress: null,
requestToSpeakTimestamp: null
}
VoiceState {
guild: <ref *1> Guild {
id: '[GUILD SNOWFLAKE]',
name: undefined,
icon: undefined,
features: undefined,
commands: GuildApplicationCommandManager {
permissions: [ApplicationCommandPermissionsManager],
guild: [Circular *1]
},
members: GuildMemberManager { guild: [Circular *1] },
channels: GuildChannelManager { guild: [Circular *1] },
bans: GuildBanManager { guild: [Circular *1] },
roles: RoleManager { guild: [Circular *1] },
presences: PresenceManager {},
voiceStates: VoiceStateManager { guild: [Circular *1] },
stageInstances: StageInstanceManager { guild: [Circular *1] },
invites: GuildInviteManager { guild: [Circular *1] },
scheduledEvents: GuildScheduledEventManager { guild: [Circular *1] },
autoModerationRules: AutoModerationRuleManager { guild: [Circular *1] },
available: false,
shardId: 0
},
id: '[USER SNOWFLAKE]',
serverDeaf: null,
serverMute: null,
selfDeaf: null,
selfMute: null,
selfVideo: null,
sessionId: null,
streaming: null,
channelId: null,
suppress: null,
requestToSpeakTimestamp: null
}
ShompiFlen
ShompiFlen15mo ago
show your client instance
bernardo
bernardoOP15mo ago
const bot = new Client({ intents: [
GatewayIntentBits.GuildVoiceStates
]});
const bot = new Client({ intents: [
GatewayIntentBits.GuildVoiceStates
]});
asking for this?
ShompiFlen
ShompiFlen15mo ago
yes, you need the guilds intent aswell to get channels
bernardo
bernardoOP15mo ago
one second let me test
ShompiFlen
ShompiFlen15mo ago
thats also why the guild object has undefined values
bernardo
bernardoOP15mo ago
thank you!!
Want results from more Discord servers?
Add your server