'message.author.id TypeError: Cannot read properties of undefined (reading 'id')

Why i didnt get message.author.id and create the channel with special permissions?

const {SlashCommandBuilder} = require("@discordjs/builders")
const { Client, Permissions } = require('discord.js');
module.exports = {
    //Create the Command 
    data: new SlashCommandBuilder()
        .setName("veranstaltung")
        .setDescription(`erstelle eine Veranstaltung`)
        .addStringOption(option1=> option1.setName("name").setDescription("Der Name der Veranstaltung").setRequired(true))
        .addStringOption(option2=> option2.setName("datum").setDescription("Das Datum der Veranstaltung").setRequired(true)),
    async execute(message){
        const name = message.options.get("name").value
        const Datum = message.options.get("datum").value
        const userid =


            //Create the Channel with Permissions
            message.guild.channels.create('new-voice', {
                type: 'GUILD_VOICE',
                permissionOverwrites: [
                    {
                        id: message.author.id,
                        deny: [Permissions.FLAGS.VIEW_CHANNEL],
                    },
                ],
            })
            .then(
                message.reply ("Der Kanal " + name + " am " + Datum + " Wurde erfolgreich erstellt")
                )

            }

}



Solution 1:[1]

It looks like you are using interactions. To access the user object, use Interaction.user, not Interaction.author (this is used in message commands). So, to access the author id, use the following:

message.user.id

Docs: https://discord.js.org/#/docs/discord.js/stable/class/Interaction?scrollTo=user

Solution 2:[2]

Slash commands are not message, they are interaction. So you should use your handler as interactionCreate and in your command file you'll edit all things according to interaction. Whenever you want to get id whos used command, you'll use;

interaction.user.id

You can look docs for more info.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harry Allen
Solution 2 Neenhila