Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  162] [ 2]  / answers: 1 / hits: 78822  / 6 Years ago, sun, april 15, 2018, 12:00:00

I tried this:



client.on('ready', () => {
let channel = client.channels.get('432462518380789771');
channel.join()
});


It doesnt work. I made sure that the ID is right and everything and its still not working.


More From » discord.js

 Answers
6

Considering we have no context on the error you're receiving, I'll provide a code example to see if this fixes your issue.



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


In this code, we use the ready event and then get the channel, like you do. In addition, we also check if the channel is undefined or null, meaning the bot was unable to find the channel or did not have it cached. Then, we join and see if we get a returning connection. If we do, log to the console the fact we successfully connected. If it didn't successfully connect, we'll catch it and error it to console.



It's always a good idea when debugging to include logging to see how far your code runs, and to see where issues may occur. In Node.js, it's also a good idea to catch for unhandledRejections. Otherwise, they will crash your process. You can do that via the code example below.



process.on(unhandledRejection, console.error);


Good luck, and happy coding!



EDIT: With the new information, I now very easily see the issue. Notice how in the error it says:



Error: FFMPEG not found


You can see that you do not currently have FFMPEG installed. To install FFMPEG, go to this url to download the sources for your platform. Check out this answer to see how to install it on Windows.


[#54658] Thursday, April 12, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleykeyshawnb

Total Points: 281
Total Questions: 99
Total Answers: 111

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
;