2017-11-21 6 views
0

Discord 봇에 대한 "help"명령을 작성하려고하는데, 그 이유를 알 수없는 것처럼 보입니다. 제거 명령도 작동하지 않지만 나머지는 작동합니다. 킥, 핑, 금지 및 말 명령은 모두 현재 작동하고 있습니다. 또한 콘솔에 봇 로그 명령 사용법을 알려주는 방법도 알아 내려고합니다. 어떤 도움을 주시면 감사하겠습니다!Discord 봇에 대한 명령이 작동하지 않습니다.

client.on("message", async message => { 
    // This event will run on every single message received, from any channel or DM. 

    // It's good practice to ignore other bots. This also makes your bot ignore itself 
    // and not get into a spam loop (we call that "botception"). 
    if(message.author.bot) return; 

    // Also good practice to ignore any message that does not start with our prefix, 
    // which is set in the configuration file. 
    if(message.content.indexOf(config.prefix) !== 0) return; 

    // Here we separate our "command" name, and our "arguments" for the command. 
    // e.g. if we have the message "+say Is this the real life?" , we'll get the following: 
    // command = say 
    // args = ["Is", "this", "the", "real", "life?"] 
    const args = message.content.slice(config.prefix.length).trim().split(/ +/g); 
    const command = args.shift().toLowerCase(); 

    // Let's go with a few common example commands! Feel free to delete or change those. 

    if(command === "ping") { 
    // Calculates ping between sending a message and editing it, giving a nice round-trip latency. 
    // The second ping is an average latency between the bot and the websocket server (one-way, not round-trip) 
    const m = await message.channel.send("Ping?"); 
    m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ping)}ms`); 
    } 

    if(command === "say") { 
    // makes the bot say something and delete the message. As an example, it's open to anyone to use. 
    // To get the "message" itself we join the `args` back into a string with spaces: 
    const sayMessage = args.join(" "); 
    // Then we delete the command message (sneaky, right?). The catch just ignores the error with a cute smiley thing. 
    message.delete().catch(O_o=>{}); 
    // And we get the bot to say the thing: 
    message.channel.send(sayMessage); 
    } 

if (command === "kick") { 
    let modRole = message.guild.roles.find("name", "[Owner]"); 
    if(message.member.roles.has(modRole.id)) { 
     let kickMember = message.guild.member(message.mentions.users.first()); 
     message.guild.member(kickMember).kick(); 
     message.channel.sendMessage("Member Kicked."); 
    } else { 
     return message.reply("You dont have the perms to kick members. scrub."); 
    } 
    } 

    if(command === "ban") { 
    let modRole = message.guild.roles.find("name", "[Owner]"); 
    if(message.member.roles.has(modRole.id)) { 
     let banMember = message.guild.member(message.mentions.users.first()); 
     message.guild.member(banMember).ban(); 
     message.channel.sendMessage("Member banned."); 
    } else { 
     return message.reply("You dont have the perms to ban members. scrub."); 
    } 

    if(command === "purge") { 
    // This command removes all messages from all users in the channel, up to 100. 

    // get the delete count, as an actual number. 
    const deleteCount = parseInt(args[0], 10); 

    // Ooooh nice, combined conditions. <3 
    if(!deleteCount || deleteCount < 2 || deleteCount > 100) 
     return message.reply("Please provide a number between 2 and 100 for the number of messages to delete"); 

    // So we get our messages, and delete them. Simple enough, right? 
    const fetched = await message.channel.fetchMessages({count: deleteCount}); 
    message.channel.bulkDelete(fetched) 
     .catch(error => message.reply(`Couldn't delete messages because of: ${error}`)); 
    } 

    if(command === "help") { 
    message.channel.send({embed: { 
     color: 3447003, 
     author: { 
     name: client.user.username, 
     icon_url: client.user.avatarURL 
     }, 
     title: "Help", 
     description: "This message contains all the info of the bot's commands", 
     fields: [{ 
      name: "d!help", 
      value: "This command can be used by everyone; displays this message" 
     }, 
     { 
      name: "d!ping", 
      value: "This command can be used by everyone; it's tells the latency of the bot and the Discord API" 
     }, 
     { 
      name: "d!kick <user>", 
      value: "This command can be used by [Owner]; it kicks a user" 
     }, 
     { 
      name: "d!ban <user>", 
      value: "This command can be used by [Owner]; it bans a user" 
     }, 
     { 
      name: "d!purge", 
      value: "This command isn't working correctly for as far as we know" 
     }   
     ], 
     timestamp: new Date(), 
     footer: { 
     text: "© DeltBot Team" 
     } 
    } 
+1

많은 양의 코드를 복사하여 붙여 넣는 것으로 나타났습니다. 게시물을 편집하여 문제 코드 만 포함 시키시겠습니까 –

+0

else if (명령 === "help")'''처럼''else if'''를 사용해야합니다. – Axium

답변

0

귀하 가져온 변수 bulkDelete는 await을 사용하고 이후 async function에 있어야합니다.