This is my first attempt to make a bot that creates a new temporary channel each time a message is posted to a specific channel. I am a bit lost now, any help appreciated.
I get this error in VSCode when I post to my channel:
DiscordAPIError[50035]: Invalid Form Body
name[BASE_TYPE_REQUIRED]: This field is required at handleErrors (c:UsersUserOneDriveJavascriptnode_modules@discordjsrestdistindex.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (c:UsersUserOneDriveJavascriptnode_modules@discordjsrestdistindex.js:1021:23)
at async SequentialHandler.queueRequest (c:UsersUserOneDriveJavascriptnode_modules@discordjsrestdistindex.js:862:14)
at async REST.request (c:UsersUserOneDriveJavascriptnode_modules@discordjsrestdistindex.js:1387:22)
at async GuildChannelManager.create (c:UsersUserOneDriveJavascriptnode_modulesdiscord.jssrcmanagersGuildChannelManager.js:170:18)
at async Client. (c:UsersUserOneDriveJavascriptbotmanager.js:19:25) {
requestBody: {
files: undefined,
json: {
name: undefined,
topic: undefined,
type: undefined,
nsfw: undefined,
bitrate: undefined,
user_limit: undefined,
parent_id: undefined,
position: undefined,
permission_overwrites: undefined,
rate_limit_per_user: undefined,
rtc_region: undefined,
video_quality_mode: undefined,
available_tags: undefined,
default_reaction_emoji: undefined,
default_auto_archive_duration: undefined,
default_sort_order: undefined,
default_forum_layout: undefined
}
},
rawError: {
code: 50035,
errors: { name: [Object] },
message: ‘Invalid Form Body’
},
code: 50035,
status: 400,
method: ‘POST’,
url: ‘https://discord.com/api/v10/guilds/[channelID]/channels’
}
My Code ——————————
`
const { token } = require("./config.json");
const Discord = require("discord.js");
const { Client, Intents, MessageEmbed, Message } = require("discord.js");
const client = new Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildMessages,
],
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on("messageCreate", async (message) => {
try {
if (message.channel.id !== "channelID") {
return;
}
// Create the temporary channel
const tempChannel = await message.guild.channels.create(
`${message.author.username}-temp-channel`,
{
type: "GUILD_TEXT",
parent: message.channel.parent,
permissionOverwrites: [
{
id: message.guild.roles.everyone,
allow: ["VIEW_CHANNEL"],
},
],
}
);
// Copy the message to the temporary channel
await tempChannel.send({
content: `Message from ${message.author.tag} in ${message.channel.name}: ${message.content}`,
files: message.attachments.map((a) => a.url), // copy any attachments
});
// Delete the temporary channel after 12 hours
setTimeout(() => {
tempChannel.delete();
}, 43200000);
} catch (error) {
console.error(error);
}
});
client.on("error", console.error);
client.login(token);
`
I have tried a bit, I think there is a problem with name, but not sure how to fix.