Discord bot stream, I try to stream but my bot allways stop the stream

const ytdlDiscord = require(“ytdl-core-discord”);
const scdl = require(“soundcloud-downloader”);
const { canModifyQueue } = require("…/util/EvobotUtil");

module.exports = {
async play(song, message) {
const { PRUNING, SOUNDCLOUD_CLIENT_ID } = require("…/config.json");
const queue = message.client.queue.get(message.guild.id);

if (!song) {
  queue.channel.leave();
  message.client.queue.delete(message.guild.id);
  return queue.textChannel.send("🚫 Music queue ended.").catch(console.error);
}

let stream = null;
let streamType = song.url.includes("youtube.com") ? "opus" : "ogg/opus";

try {
  if (song.url.includes("youtube.com")) {
    stream = await ytdlDiscord(song.url, { highWaterMark: 1 << 25 });
  } else if (song.url.includes("soundcloud.com")) {
    try {
      stream = await scdl.downloadFormat(song.url, scdl.FORMATS.OPUS, SOUNDCLOUD_CLIENT_ID ? SOUNDCLOUD_CLIENT_ID : undefined);
    } catch (error) {
      stream = await scdl.downloadFormat(song.url, scdl.FORMATS.MP3, SOUNDCLOUD_CLIENT_ID ? SOUNDCLOUD_CLIENT_ID : undefined);
      streamType = "unknown";
    }
  }
} catch (error) {
  if (queue) {
    queue.songs.shift();
    module.exports.play(queue.songs[0], message);
  }

  console.error(error);
  return message.channel.send(`Error: ${error.message ? error.message : error}`);
}

queue.connection.on("disconnect", () => message.client.queue.delete(message.guild.id));

const dispatcher = queue.connection
  .play(stream, { type: streamType })
  .on("finish", () => {
    if (collector && !collector.ended) collector.stop();

    if (queue.loop) {
      // if loop is on, push the song back at the end of the queue
      // so it can repeat endlessly
      let lastSong = queue.songs.shift();
      queue.songs.push(lastSong);
      module.exports.play(queue.songs[0], message);
    } else {
      // Recursively play the next song
      queue.songs.shift();
      module.exports.play(queue.songs[0], message);
    }
  })
  .on("error", (err) => {
    console.error(err);
    queue.songs.shift();
    module.exports.play(queue.songs[0], message);
  });
dispatcher.setVolumeLogarithmic(queue.volume / 100);

try {
  var playingMessage = await queue.textChannel.send(`🎶 Started playing: **${song.title}** ${song.url}`);
  await playingMessage.react("⏭");
  await playingMessage.react("⏯");
  await playingMessage.react("🔁");
  await playingMessage.react("⏹");
} catch (error) {
  console.error(error);
}

const filter = (reaction, user) => user.id !== message.client.user.id;
var collector = playingMessage.createReactionCollector(filter, {
  time: song.duration > 0 ? song.duration * 1000 : 600000
});

collector.on("collect", (reaction, user) => {
  if (!queue) return;
  const member = message.guild.member(user);

  switch (reaction.emoji.name) {
    case "⏭":
      queue.playing = true;
      reaction.users.remove(user).catch(console.error);
      if (!canModifyQueue(member)) return;
      queue.connection.dispatcher.end();
      queue.textChannel.send(`${user} ⏩ skipped the song`).catch(console.error);
      collector.stop();
      break;

    case "⏯":
      reaction.users.remove(user).catch(console.error);
      if (!canModifyQueue(member)) return;
      if (queue.playing) {
        queue.playing = !queue.playing;
        queue.connection.dispatcher.pause(true);
        queue.textChannel.send(`${user} ⏸ paused the music.`).catch(console.error);
      } else {
        queue.playing = !queue.playing;
        queue.connection.dispatcher.resume();
        queue.textChannel.send(`${user} ▶ resumed the music!`).catch(console.error);
      }
      break;

    case "🔁":
      reaction.users.remove(user).catch(console.error);
      if (!canModifyQueue(member)) return;
      queue.loop = !queue.loop;
      queue.textChannel.send(`Loop is now ${queue.loop ? "**on**" : "**off**"}`).catch(console.error);
      break;

    case "⏹":
      reaction.users.remove(user).catch(console.error);
      if (!canModifyQueue(member)) return;
      queue.songs = [];
      queue.textChannel.send(`${user} ⏹ stopped the music!`).catch(console.error);
      try {
        queue.connection.dispatcher.end();
      } catch (error) {
        console.error(error);
        queue.connection.disconnect();
      }
      collector.stop();
      break;

    default:
      reaction.users.remove(user).catch(console.error);
      break;
  }
});

collector.on("end", () => {
  playingMessage.reactions.removeAll().catch(console.error);
  if (PRUNING && playingMessage && !playingMessage.deleted) {
    playingMessage.delete({ timeout: 3000 }).catch(console.error);
  }
});

}
};

and another code

const { play } = require("…/include/play");
const { YOUTUBE_API_KEY, SOUNDCLOUD_CLIENT_ID } = require("…/config.json");
const ytdl = require(“ytdl-core”);
const YouTubeAPI = require(“simple-youtube-api”);
const youtube = new YouTubeAPI(YOUTUBE_API_KEY);
const scdl = require(“soundcloud-downloader”);

module.exports = {
name: “play”,
cooldown: 3,
aliases: [“p”],
description: “Plays audio from YouTube or Soundcloud”,
async execute(message, args) {
const { channel } = message.member.voice;

const serverQueue = message.client.queue.get(message.guild.id);
if (!channel) return message.reply("You need to join a voice channel first!").catch(console.error);
if (serverQueue && channel !== message.guild.me.voice.channel)
  return message.reply(`You must be in the same channel as ${message.client.user}`).catch(console.error);

if (!args.length)
  return message
    .reply(`Usage: ${message.client.prefix}play <YouTube URL | Video Name | Soundcloud URL>`)
    .catch(console.error);

const permissions = channel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT"))
  return message.reply("Cannot connect to voice channel, missing permissions");
if (!permissions.has("SPEAK"))
  return message.reply("I cannot speak in this voice channel, make sure I have the proper permissions!");

const search = args.join(" ");
const videoPattern = /^(https?:\/\/)?(www\.)?(m\.)?(youtube\.com|youtu\.?be)\/.+$/gi;
const playlistPattern = /^.*(list=)([^#\&\?]*).*/gi;
const scRegex = /^https?:\/\/(soundcloud\.com)\/(.*)$/;
const url = args[0];
const urlValid = videoPattern.test(args[0]);

// Start the playlist if playlist url was provided
if (!videoPattern.test(args[0]) && playlistPattern.test(args[0])) {
  return message.client.commands.get("playlist").execute(message, args);
}

const queueConstruct = {
  textChannel: message.channel,
  channel,
  connection: null,
  songs: [],
  loop: false,
  volume: 100,
  playing: true
};

let songInfo = null;
let song = null;

if (urlValid) {
  try {
    songInfo = await ytdl.getInfo(url);
    song = {
      title: songInfo.videoDetails.title,
      url: songInfo.videoDetails.video_url,
      duration: songInfo.videoDetails.lengthSeconds
    };
  } catch (error) {
    console.error(error);
    return message.reply(error.message).catch(console.error);
  }
} else if (scRegex.test(url)) {
  try {
    const trackInfo = await scdl.getInfo(url, SOUNDCLOUD_CLIENT_ID);
    song = {
      title: trackInfo.title,
      url: trackInfo.permalink_url,
      duration: trackInfo.duration / 1000
    };
  } catch (error) {
    if (error.statusCode === 404)
      return message.reply("Could not find that Soundcloud track.").catch(console.error);
    return message.reply("There was an error playing that Soundcloud track.").catch(console.error);
  }
} else {
  try {
    const results = await youtube.searchVideos(search, 1);
    songInfo = await ytdl.getInfo(results[0].url);
    song = {
      title: songInfo.videoDetails.title,
      url: songInfo.videoDetails.video_url,
      duration: songInfo.videoDetails.lengthSeconds
    };
  } catch (error) {
    console.error(error);
    return message.reply("No video was found with a matching title").catch(console.error);
  }
}

if (serverQueue) {
  serverQueue.songs.push(song);
  return serverQueue.textChannel
    .send(`✅ **${song.title}** has been added to the queue by ${message.author}`)
    .catch(console.error);
}

queueConstruct.songs.push(song);
message.client.queue.set(message.guild.id, queueConstruct);

try {
  queueConstruct.connection = await channel.join();
  await queueConstruct.connection.voice.setSelfDeaf(true);
  play(queueConstruct.songs[0], message);
} catch (error) {
  console.error(error);
  message.client.queue.delete(message.guild.id);
  await channel.leave();
  return message.channel.send(`Could not join the channel: ${error}`).catch(console.error);
}

}
};

WHER HE HAVE ERROR???

Can you show us your logs?

Yep but in logs consol have not erros

Do you have discord mybe?

Can you open the console and run:
curl -I https://discordapp.com/api/v7/gateway

Do you think on Treminal?

The terminal, I mean.

$ discordapp. com/api/v7/gateway
-su: discordapp. com/api/v7/gateway: No such file or directory

It should be this ^^^

what i can do with this?

$ curl -I https://discordapp.com/api/v7/gateway
HTTP/1.1 200 OK
Date: Sat, 29 Aug 2020 22:47:47 GMT
Content-Type: application/json
Content-Length: 35
Connection: keep-alive
Set-Cookie: __cfduid=d9218818f8c4bf10c4c7908f8712e298c1598741267; expires=Mon, 28-Sep-20 22:47:47 GMT; path=/; domain=.discordapp.com; HttpOnly; SameSite=Lax
strict-transport-security: max-age=31536000; includeSubDomains
x-envoy-upstream-service-time: 2
Via: 1.1 google
CF-Cache-Status: HIT
Age: 28437
Expires: Sat, 29 Aug 2020 23:17:47 GMT
Cache-Control: public, max-age=1800
Accept-Ranges: bytes
cf-request-id: 04de00db5000009fca0e13c200000001
Expect-CT: max-age=604800, report-uri=“https ://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct”
Server: cloudflare
CF-RAY: 5ca9d0d88c9e9fca-IAD

This knocked me out when I knocked on the terminal