discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.39k stars 3.97k forks source link

"client.channels.fetch" problem #3951

Closed Dunkelsan closed 4 years ago

Dunkelsan commented 4 years ago

The error is "client is not defined", but already i change "run(message)" for "run(client, message)" the new error is "TypeError: Cannot read property 'fetch' of undefined".... im so confused, can you help me?

const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js');
const Youtube = require('simple-youtube-api');
const ytdl = require('ytdl-core');
const { youtubeAPI } = require('../../config.json');
const youtube = new Youtube(youtubeAPI);

module.exports = class ResumeCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'song',
      aliases: ['song', 'voice'],
      memberName: 'song',
      group: 'music',
      description: 'Listen song',
      guildOnly: true
    });
  }

  run(message) {

    let voiceChannel = client.channels.fetch('XXXXXXXXXXXX9349');  <<<<< HERE IS THE PROBLEM!!

    if(!voiceChannel) return message.channel.send('¡Error!.');

    voiceChannel.join()
      .then(connection => {

        const url = ytdl('https://www.youtube.com/watch?v=XXXXXXXXX', { filter : 'audioonly' });
        const dispatcher = connection.play(url);
        dispatcher.on('finish', () => {

          setTimeout(function(){ 
          return message.guild.me.voice.channel.leave(); 
          }, 15000);

        })

        message.delete();

      })

      .catch(console.error);
  }
};
SpaceEEC commented 4 years ago

The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the Discord server instead of opening an issue – you will get redirected there anyway.