Discord.js Get A Bot To Join A Music Chanel 1

Discord.js Get A Bot To Join A Music Chanel

client.on("ready", () => {
  const channel = client.channels.get("mychannelid");
  if (!channel) return console.error("The channel does not exist!");
  channel.join().then(connection => {
    // Yay, it worked!
    console.log("Successfully connected.");
  }).catch(e => {
    // Oh no, it errored! Let's log it to console 🙂
    console.error(e);
  });
});

Here is what the above code is Doing:
1. We’re getting the channel by its ID.
2. We’re joining the channel.
3. We’re logging a message to console if the connection is successful.
4. We’re logging the error to console if the connection fails.

Now, let’s say you want to play a file. You can do that by using the following code:

Similar Posts