daryl.
daryl.
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
of course)
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
well, i did it. correct?
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
oke, i'll try
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
i should update it step-by-step u mean?
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
it's worked just on level "it's online", that's it
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
yeah, i understand, that's why i launched it on v12
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
yup, he goes djs is v12, i updated it to v14 and the code broke
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
it's the last line i just deleted it, i think people don't need to see the token :))
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
}
} else {
console.log('Could not find the guild for this voice channel.');
}
});
}
});
}
} else {
console.log('Could not find the guild for this voice channel.');
}
});
}
});
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
// 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.');
// 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.');
30 replies
DIAdiscord.js - Imagine a bot
Created by daryl. on 12/29/2023 in #djs-questions
Bot doesn't send a message
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;
}
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;
}
30 replies