简体   繁体   English

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

[英]How do I create a case statement in discord.js

This code is what i am using now to have a rough idea of what to do 这段代码是我现在用来大致了解要做什么的代码

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

How would i create a case statement based on what was given in the input and how to return the outcome? 我将如何基于输入中给出的内容以及如何返回结果来创建案例陈述?

You're going to have to look into async / await functions, so that on a message, you can run a certain function. 您将不得不研究async / await功能,以便在消息上可以运行某个功能。 Tutorial on async/await 异步/等待教程

Essentially you send the prompt: 本质上,您发送提示:

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

then await to wait for a response and you can use the result in your switch statement. 然后await响应,然后可以在switch语句中使用结果。

Edit: You don't have to look into async/await consider using this solution: Waiting for reply with discord.js 编辑:您不必研究async/await考虑使用此解决方案: 等待与discord.js的答复

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

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