! Midny
DIAdiscord.js - Imagine an app
•Created by ! Midny on 8/4/2024 in #djs-questions
Error : Could not resolve channel to GUILD_VOICE
alroght thank u
6 replies
DIAdiscord.js - Imagine an app
•Created by ! Midny on 8/4/2024 in #djs-questions
Error : Could not resolve channel to GUILD_VOICE
heres the code yeah
6 replies
DIAdiscord.js - Imagine an app
•Created by ! Midny on 8/4/2024 in #djs-questions
Error : Could not resolve channel to GUILD_VOICE
const { SlashCommandBuilder } = require('discord.js');
const { getGuild } = require("../guildHandler");
module.exports = {
delete: true,
data: new SlashCommandBuilder()
.setName('create')
.setDescription('Creates an Event on the Server!')
.addStringOption(option =>
option.setName('name')
.setDescription('Name of the event')
.setRequired(true))
.addStringOption(option =>
option.setName('description')
.setDescription('Description of the event')
.setRequired(true))
.addStringOption(option =>
option.setName('starttime')
.setDescription('Start time of the event (ISO format)')
.setRequired(true))
.addStringOption(option =>
option.setName('endtime')
.setDescription('End time of the event (ISO format)')
.setRequired(true))
.addChannelOption(option =>
option.setName('location')
.setDescription('Location of the event (Voice Channel)')
.setRequired(true))
.addIntegerOption(option =>
option.setName('privacylevel')
.setDescription('Privacy level of the event (1 = Public, 2 = Guild Only)')
.setRequired(false)),
run: async ({ interaction }) => {
const name = interaction.options.getString('name');
const description = interaction.options.getString('description');
const startTime = interaction.options.getString('starttime');
const endTime = interaction.options.getString('endtime');
const location = interaction.options.getChannel('location');
const privacyLevel = interaction.options.getInteger('privacylevel') || 1; // Default to public if not provided
const isValidDate = (dateString) => {
const regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
return regex.test(dateString);
};
if (!isValidDate(startTime) || !isValidDate(endTime)) {
return interaction.reply("Invalid date format. Please use ISO format.");
}
console.log(location)
const guild = getGuild();
if (!guild) {
return interaction.reply("Guild not found.");
}
try {
const event = await guild.scheduledEvents.create({
name,
description,
scheduledStartTime: new Date(startTime).toISOString(),
scheduledEndTime: new Date(endTime).toISOString(),
location: location.id, // Use channel ID here
privacyLevel
});
await interaction.reply(
Created an event with the following details:\n```json\n${JSON.stringify(event, null, 2)}\n```);
} catch (error) {
console.error("Error creating event:", error);
await interaction.reply("There was an error creating the event.");
}
}
};
6 replies