Discord bot简单编辑自己的消息给我错误

时间:2020-09-13 22:03:05

标签: javascript node.js discord discord.js

module.exports = {
 name: 'hack',

 execute: function(message, args) {
  const user = message.mentions.users.first() || args[0];

  const member = message.guild.member(user);

  if (member) {
   message.channel
    .send('Scrambling Through Database')

    .then((message) => {
     setTimeout(function() {
      message.edit(`Working on hack`);
     }, 4000);
    });

   setTimeout(function() {
    message.edit(`Inserting Trojan File on ?:computer_mouse:`);
   }, 2700);

   setTimeout(function() {
    message.edit(member + ` Leaking there passwords to the russians`);
   }, 1700);

   setTimeout(function() {
    message.edit(`Deleting saved passwords`);
   }, 1700);

   setTimeout(function() {
    message.edit(`Deleted Epic Account`);
   }, 1700);

   setTimeout(function() {
    message.edit(`Sent a screenshot of there browser history to there friends`);
   }, 1700);

   setTimeout(function() {
    message.edit(`Leaking IP Address`);
   }, 1700);

   setTimeout(function() {
    message.edit(`Leaking users gmail account`);
   }, 1700);

   setTimeout(function() {
    message.edit(`Completing hack`);
   }, 3700);

   setTimeout(function() {
    message.edit(`Deleting traces`);
   }, 2000);

   setTimeout(function() {
    message.edit(`Deleting traces...`);
   }, 2000);

   setTimeout(function() {
    message.edit(`Copied User Details`);
   }, 2000);

   setTimeout(function() {
    message.edit(`A successful hack was complete and it was real`);
   }, 3000);
  } else {
   message.channel.send(
    'Who are you even trying to hack? Is it that tough to mention a user?'
   );
  }
 },
};

所以这是一个简单的!hack @user命令,并且在您使用该命令后,机器人仅发送一条消息并不断对其消息进行多次编辑,但是由于某种原因我遇到了错误。 这是错误:

UnhandledPromiseRejection警告:DiscordAPIError:无法编辑其他用户创作的消息

1 个答案:

答案 0 :(得分:0)

client.on('message')中,“ message”变量与“ message”变量具有完全相同的名称,因此将其更改为“ msg”,然后一切都会正常进行:

module.exports = {
 name: 'hack',
 execute: function(message, args) {
  const user = message.mentions.users.first() || args[0];

  const member = message.guild.member(user);

  if (member) {
   message.channel
    .send('Scrambling Through Database')

    .then((msg) => {
     setTimeout(function() {
      msg.edit(`Working on hack`);
     }, 4000);
    });

   // all codings

   setTimeout(function() {
    msg.edit(`A successful hack was complete and it was real`);
   }, 3000);
  } else {
   message.channel.send(
    'Who are you even trying to hack? Is it that tough to mention a user?'
   );
  }
 },
};