简体   繁体   中英

Discord.JS - I am getting 'Application did not respond' but no errors in console

So I'm not getting any errors in the console with this code but it is causing an error in discord where it just says 'Application did not respond'. I'm just wondering if there is something I am doing wrong. I have tried following the Discord.JS official documentation/guides to get this far.

This is all in a command handler.

My desired outcome is to mention the author of the message .

  const { Client, SlashCommandBuilder, GatewayIntentBits } = require('discord.js');
    const client = new Client({ intents: [GatewayIntentBits.Guilds] });
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('cleanthedecks')
            .setDescription('Tells a user to clean the decks'),
        async execute(interaction) {
            client.on('message', (message) => {
                const user = message.author;
                await interaction.reply(`${user} Get the decks cleaned immediately with /deckscrub`);
                console.log(user);
            })
        }
    }

Ok I figured it out. I can just use the 'interaction' class to get the user and on top of that the username.

So my working code is

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('cleanthedecks')
        .setDescription('Tells a user to clean the decks'),
    async execute(interaction) {
        const user = interaction.user.username;
        await interaction.reply(`${user} Get the decks cleaned immediately with /deckscrub`);
        console.log(user);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM