简体   繁体   中英

Trying to delete the message of a discord bot in discord.js 5 seconds after sending, getting an error

First of all, I am very new to any kind of programming, this is within my first 3 hours.

As I said, I am trying to get the bot to delete its "clear" message a few seconds after saying it. This is how I tried it:

if (msg.member.hasPermission("ADMINISTRATOR") || msg.member.roles.cache.find(r => r.name === "Clear Perm")) {
  if (!args[1] || args[1] > 99 || args[1] < 1) {
    msg.channel.send('Invalid Argument Given, Please Provide An Amount Of Messages Between 1-99 To Be Deleted')
  } else {
    var BD = parseInt(args[1]) + 1;

    function DelCount() {
      msg.channel.send("`I Have Deleted " + args[1] + " Message(s)`");
    }

    msg.channel.bulkDelete(BD);
    setTimeout(DelCount, 10);
    setTimeout(() => msg.delete(msg.content.includes('I Have Deleted')), 5000)
  }
  if (!msg.member.hasPermission("ADMINISTRATOR") && !msg.member.roles.cache.find(r => r.name === "Clear Perm")) {
    msg.channel.send("You Do Not Have Permission To Clear Chat");
  }
}

When I do it like this I get the following error:

C:\Users\Rick\Desktop\Discord Bot\KendanK\node_modules\discord.js\src\structures\Message.js:501
    if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
                                     ^

TypeError [INVALID_TYPE]: Supplied options is not an object.
    at Message.delete (C:\Users\Rick\Desktop\Discord Bot\KendanK\node_modules\discord.js\src\structures\Message.js:501:44)
    at Timeout._onTimeout (C:\Users\Rick\Desktop\Discord Bot\KendanK\index.js:170:48)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7) {
  [Symbol(code)]: 'INVALID_TYPE'
}

Does anyone know what I am doing wrong and what I should do instead?

First of all, I am very new to any kind of programming, this is within my first 3 hours.

As I said, I am trying to get the bot to delete its "clear" message a few seconds after saying it. This is how I tried it:

if (msg.member.hasPermission("ADMINISTRATOR") || msg.member.roles.cache.find(r => r.name === "Clear Perm")) {
  if (!args[1] || args[1] > 99 || args[1] < 1) {
    msg.channel.send('Invalid Argument Given, Please Provide An Amount Of Messages Between 1-99 To Be Deleted')
  } else {
    var BD = parseInt(args[1]) + 1;

    function DelCount() {
      msg.channel.send("`I Have Deleted " + args[1] + " Message(s)`");
    }

    msg.channel.bulkDelete(BD);
    setTimeout(DelCount, 10);
    setTimeout(() => msg.delete(msg.content.includes('I Have Deleted')), 5000)
  }
  if (!msg.member.hasPermission("ADMINISTRATOR") && !msg.member.roles.cache.find(r => r.name === "Clear Perm")) {
    msg.channel.send("You Do Not Have Permission To Clear Chat");
  }
}

When I do it like this I get the following error:

C:\Users\Rick\Desktop\Discord Bot\KendanK\node_modules\discord.js\src\structures\Message.js:501
    if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
                                     ^

TypeError [INVALID_TYPE]: Supplied options is not an object.
    at Message.delete (C:\Users\Rick\Desktop\Discord Bot\KendanK\node_modules\discord.js\src\structures\Message.js:501:44)
    at Timeout._onTimeout (C:\Users\Rick\Desktop\Discord Bot\KendanK\index.js:170:48)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7) {
  [Symbol(code)]: 'INVALID_TYPE'
}

Does anyone know what I am doing wrong and what I should do instead?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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