whos there
whos there
DIAdiscord.js - Imagine a bot
Created by whos there on 9/12/2023 in #djs-questions
Don't DM a user with disabled DMs?
Is it possible for the bot to first check if a user has completely disabled DMs. And if so do not send a DM.
6 replies
DIAdiscord.js - Imagine a bot
Created by whos there on 3/1/2023 in #djs-questions
I am attempting to allow a user to update the topic of a channel to include a unix timestamp
The code that seems to always produce a timestamp that is 10 hours early
} else if (command === 'updateraidtime') {
const month = args.getString('month', true);
const day = args.getInteger('day', true);
const time = args.getString('time', true);
const year = args.getInteger('year', true);
const nextRaidOption = args.getString('next_raid', true);

const guild = interaction.guild;
const channelOption = args.getChannel('channel_name', true);

if (!guild || !channelOption || channelOption.type !== 'GUILD_TEXT') {
await interaction.reply('You need to specify a valid text channel.');
return;
}

const channel = channelOption;

// Validate month
const monthNum = parseInt(month);
if (isNaN(monthNum) || monthNum < 1 || monthNum > 12) {
await interaction.reply('You need to specify a valid month between 1 and 12.');
return;
}

// Validate day
if (day < 1 || day > 31) {
await interaction.reply('You need to specify a valid day between 1 and 31.');
return;
}

// Validate time
const timeRegex = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/;
if (!timeRegex.test(time)) {
await interaction.reply('You need to specify a valid time in the format HH:MM.');
return;
}

// Split time into hours and minutes
const [hours, minutes] = time.split(':');

// Build timestamp and format it
const timestamp = new Date(year, monthNum - 1, day, hours, minutes);
const formattedTimestamp = `<t:${Math.floor((timestamp.getTime() - timestamp.getTimezoneOffset() * 60 * 1000) / 1000)}:f>`;

// Update channel topic with timestamp and next raid information
await channel.setTopic(`Next meet is ${formattedTimestamp} ${nextRaidOption}`);

await interaction.reply('Raid time updated successfully!');
}
} else if (command === 'updateraidtime') {
const month = args.getString('month', true);
const day = args.getInteger('day', true);
const time = args.getString('time', true);
const year = args.getInteger('year', true);
const nextRaidOption = args.getString('next_raid', true);

const guild = interaction.guild;
const channelOption = args.getChannel('channel_name', true);

if (!guild || !channelOption || channelOption.type !== 'GUILD_TEXT') {
await interaction.reply('You need to specify a valid text channel.');
return;
}

const channel = channelOption;

// Validate month
const monthNum = parseInt(month);
if (isNaN(monthNum) || monthNum < 1 || monthNum > 12) {
await interaction.reply('You need to specify a valid month between 1 and 12.');
return;
}

// Validate day
if (day < 1 || day > 31) {
await interaction.reply('You need to specify a valid day between 1 and 31.');
return;
}

// Validate time
const timeRegex = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/;
if (!timeRegex.test(time)) {
await interaction.reply('You need to specify a valid time in the format HH:MM.');
return;
}

// Split time into hours and minutes
const [hours, minutes] = time.split(':');

// Build timestamp and format it
const timestamp = new Date(year, monthNum - 1, day, hours, minutes);
const formattedTimestamp = `<t:${Math.floor((timestamp.getTime() - timestamp.getTimezoneOffset() * 60 * 1000) / 1000)}:f>`;

// Update channel topic with timestamp and next raid information
await channel.setTopic(`Next meet is ${formattedTimestamp} ${nextRaidOption}`);

await interaction.reply('Raid time updated successfully!');
}
I have tried several variations and can not seem to get this figured out. Any help would be appreciated.
4 replies