ygreq Idraless
ygreq Idraless

Reputation: 1

ERROR message.guild.channels.filter is not a function, using Discord.JS

I'm working on a Discord bot using discord.js. And I want him to play MP3 when I type !play. But I have an error message "message.guild.channels.filter". I'm noob in this domain and I don't understand why. The code :


module.exports = class Play extends Command {
    static match(message) {
        return message.content.startsWith('!play')
    }

    static action (message){
       let voiceChannel =  message.guild.channels
        .filter(function (channel) {return channel.type === 'voice'})
        .first()
        voiceChannel
        .join()
        .then(function (connection){
            connection.playFile('./ah.mp3')
        })
    }
}

Upvotes: 0

Views: 2501

Answers (1)

Syntle
Syntle

Reputation: 5174

Since discord.js v12 you now need to use .cache to access channels collection.

Use client.channels.cache.filter() instead.

Upvotes: 2

Related Questions