如何在 discord.js 中创建 case 语句

Posted

技术标签:

【中文标题】如何在 discord.js 中创建 case 语句【英文标题】:How do I create a case statement in discord.js 【发布时间】:2018-06-26 08:50:17 【问题描述】:

这段代码是我现在用来大致了解要做什么的代码

bot.on('message', (message) => 
    if (messege.content.includes) 
        int (num = 0);
        switch(num) 
            case 1:
                System.out.println('The IP of the server is .');
            case 2:
                System.out.println('The Store is');
            case 3:
                System.out.println('Disord instant link : ');
            default:
                System.out.println('Sorry ');
        
    
);
bot.on('message', (message) => 
   if(message.content == (prefix + 'help')) 
        message.channel.sendMessage('With what may you like help?');
        message.reply('Enter 1, ...');
        message.reply('Enter 2, Stores link!');
        message.reply('Enter 3, discord instant link');
    
);

我将如何根据输入中给出的内容创建案例陈述以及如何返回结果?

【问题讨论】:

您还在寻找解决方案吗?我有点困惑你为什么使用System.out.println -> 这是一个java函数,但不是javascript。与int (num = 0); 相同。 【参考方案1】:

您将不得不查看async / await 函数,以便在消息上运行某个函数。 Tutorial on async/await

本质上是你发送提示:

message.channel.send('With what may you like help?');

然后await 等待响应,您可以在 switch 语句中使用结果。

编辑:您不必查看async/await 考虑使用此解决方案:Waiting for reply with discord.js

【讨论】:

以上是关于如何在 discord.js 中创建 case 语句的主要内容,如果未能解决你的问题,请参考以下文章