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.
3 Replies
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey16mo ago
When you say 10 hours early, what timezone are you in
whos there
whos there16mo ago
I'm in Hawaii. The bot is hosted in a docker container on a server in Germany. ... I had not considered the Dockers timezone setting because I thought unixtimestamp and formatted for discord syntax would ignore the origin time zone