简体   繁体   English

如何取消整个 Discord 应用程序

[英]How can you cancel your whole Discord Application

So I'm creating a Discord Application bot, Ban appeal Application that works within DM's only.所以我正在创建一个 Discord 应用程序机器人,禁止上诉应用程序,仅在 DM 中工作。 I type the command p!apply and start the application, however whenever I try to cancel the application by typing cancel it only replies and does not actually cancel the whole form.我输入命令p!apply并启动应用程序,但是每当我尝试通过输入cancel来取消应用程序时,它只会回复并且实际上不会取消整个表单。

Here's my code:这是我的代码:

let userApplications = {}


client.on("message", function(message) {
    if (message.author.equals(client.user)) return;
  
    let authorId = message.author.id;
  
    if (message.content === prefix + "apply") {
        if (!(authorId in userApplications)) {
            userApplications[authorId] = { "step" : 1}
  
            message.author.send("**__Team PhyZics Discord Ban Appeal Form__** \n  If you're applying to get unbanned from our server, please fill this application out. We do not accept all applications, so take this application seriously and take your time when filling this out. \n \n - If you want to cancel this application please type `cancel`");
            message.author.send("**Question 1: Which server did you get banned from?**");
        }
  
    } else {
  
        if (message.channel.type === "dm" && authorId in userApplications) {
            if (message.content.toLowerCase() === 'cancel') {
                return message.author.send('Application Cancelled');
                
               
            }
            let authorApplication = userApplications[authorId];
  
            if (authorApplication.step == 1 ) {
                authorApplication.answer1 = message.content;
                message.author.send("**Question 2: Why did you get banned/What reason did you get banned for?**");
                authorApplication.step ++;
            }
            else if (authorApplication.step == 2) {
                authorApplication.answer2 = message.content;
                message.author.send("**Question 3: Why do you want to get unbanned?**");
                authorApplication.step ++;
            }
            else if (authorApplication.step == 3) {
                authorApplication.answer3 = message.content;
                message.author.send("**Question 4: Any questions or concerns? If not, please type `no`.**");
                authorApplication.step ++;
            }
  
            else if (authorApplication.step == 4) {
                authorApplication.answer4 = message.content;
                message.author.send("Your application has been submitted, please be patient and do not ask any staff member regarding to your ban appeal.");
                client.channels.cache.get("790376360848785419")
                  .send(`**${message.author.tag}'s Application** \n **Q1**: ${authorApplication.answer1} \n **Q2:** ${authorApplication.answer2} \n **Q3:** ${authorApplication.answer3} \n **Q4:** ${authorApplication.answer4} `);
                delete userApplications[authorId];
            }
        }
    }
});

enter image description here在此处输入图像描述

You're getting this problem because you're only returning a message Application cancelled without actually removing the user from your userApplications object.您遇到此问题是因为您只返回一条消息Application cancelled ,而没有实际从您的userApplications object 中删除用户。

To fix this, all you have to do is delete the entry from your object when the user cancels, like so:要解决此问题,您只需在用户取消时从 object 中删除该条目,如下所示:

if (message.content.toLowerCase() === 'cancel') {
    delete userApplications[authorId];

    return message.author.send('Application Cancelled');
}

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

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