#Bot doesn't send a message
29 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGES] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('voiceStateUpdate', (oldState, newState) => {
console.log('voiceStateUpdate event triggered');
if (oldState.channelId && newState.channelId && oldState.channelId === newState.channelId) {
// User changed their voice settings (e.g., muted/unmuted, deafened/undeafened)
return;
}
// Check if the user has just joined a voice channel
if (!oldState.channelId && newState.channelId) {
// User has joined a voice channel
voiceStates.set(newState.id, {channelId: newState.channelId, joinTime: Date.now()});
} else if (oldState.channelId && !newState.channelId) {
// User has left a voice channel
const joinTime = voiceStates.get(oldState.id).joinTime;
const leaveTime = Date.now();
const timeDifference = leaveTime - joinTime;
const hours = Math.floor(timeDifference / (1000 * 60 * 60));
const minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
const timeSpent = `${hours} hours and ${minutes} minutes`;
voiceStates.delete(oldState.id);
// Get the text channel associated with the voice channel where the user has just left
client.guilds.fetch(oldState.guild.id)
.then(guild => {
if (guild) {
const textChannel = guild.channels.cache.find(channel => channel.type === 'text');
if (textChannel) {
// Check if the bot can send messages in the text channel
const permissions = textChannel.permissionsFor(client.user);
if (permissions.has('SEND_MESSAGES')) {
// The bot can send messages in the channel, so proceed with sending the message
console.log(`User ${oldState.member.user.tag} spent ${timeSpent} in the voice channel.`)
textChannel.send(`User ${oldState.member.user.tag} spent ${timeSpent} in the voice channel.`);
} else {
console.log('The bot does not have permission to send messages in this text channel.');
}
} else {
console.log('No text channel found for this guild.');
}
} else {
console.log('Could not find the guild for this voice channel.');
}
});
}
});
i dont see where you call client.login(...)
it's the last line
i just deleted it, i think people don't need to see the token :))
thats why you store it in another file
does your bot go online?
whats your djs version?
npm ls discord.js
yup, he goes
djs is v12, i updated it to v14 and the code broke
that code is most definitely not v14
and yes your code will break
its 2 major versions
yeah, i understand, that's why i launched it on v12
it's worked just on level "it's online", that's it
please show the output of npm ls discord.js
you'll want to look at the v13 guide first, then the v14 guide
Additional Information: Updating from v12 to v13
read more
Additional Information: Updating from v13 to v14
read more
i should update it step-by-step u mean?
yes
oke, i'll try
unfortunately, we don't support v12 anymore so you will need to update to at least v13, but i suggest going from 13 to 14
well, i did it. correct?