admin管理员组

文章数量:1296311

I am simply trying to make a bot join a voice channel as a placeholder so i can make a music bot play 24/7.

One of the codes that I found on stackoverflow was:

  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);
  });
});

but this didn't seem to work for me. This is what the visual studio code output said

Do you know how I could solve this problem or tell me the right way to do this?

I am simply trying to make a bot join a voice channel as a placeholder so i can make a music bot play 24/7.

One of the codes that I found on stackoverflow was:

  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);
  });
});

but this didn't seem to work for me. This is what the visual studio code output said

Do you know how I could solve this problem or tell me the right way to do this?

Share edited Dec 23, 2020 at 0:43 peterh 1 asked Jun 24, 2020 at 21:07 One Bass ManOne Bass Man 371 gold badge1 silver badge8 bronze badges 1
  • 1 Due to recent updates StackOverflow answers for discord.js are typically outdated. There's not much need to look at them anyway. The discord.js docs have plenty of examples and is very well put together. In this case you'd be wondering why client.channels.get isn't a function, so check the docs on client.channels and you'll see that it's now a ChannelManager and you need to access the cache property instead, as in Jakye's answer. – Klaycon Commented Jun 24, 2020 at 21:15
Add a ment  | 

1 Answer 1

Reset to default 3

Looks like you're using Discord.js V12. To get the channel you'll have to use:

client.channels.cache.get("ChannelID")

本文标签: javascriptHow do I make a discord bot join a voice channelStack Overflow