简体   繁体   English

Discord.JS - 我收到“应用程序没有响应”但控制台中没有错误

[英]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'.因此,我在控制台中没有使用此代码收到任何错误,但它在 discord 中导致错误,它只是说“应用程序没有响应”。 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.我已经尝试按照 Discord.JS 官方文档/指南来做到这一点。

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.我可以只使用“交互” class 来获取用户以及用户名。

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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