Discord.js静音命令和创建静音角色不起作用并给出错误

时间:2020-08-16 14:30:30

标签: javascript node.js discord.js

我正在尝试创建一个静音命令。如果未创建Muted角色,我希望该漫游器自动创建一个角色并覆盖每个频道权限,以使具有该角色的用户无法发送消息。

我的代码:

bot.on('message', (message) => {
  const args = message.content.substring(PREFIX.length).split(' ');

  switch (args[0]) {
    case 'mute':
      const person = message.guild.member(
        message.mentions.users.first() && message.guild.members.fetch(args[1])
      );
      if (!person) return message.reply("Couldn't find that member!");
      if (person.hasPermission('MANAGE_MESSAGES'))
        return message.reply("You don't have permissions to mute members!");

      const muterole = message.guild.roles.fetch(
        (role) => role.name === 'Muted'
      );

      if (!muterole) {
        muterole = message.guild.roles.create(
          (name = 'Muted'),
          (color = 0x000000),
          Permissions('VIEW_CHANNEL')
        );
        message.channel.updateOverwrite(muterole, { SEND_MESSAGES: false });
      }

      const time = args[2];

      if (!time)
        return message.reply('How many time do you want him to be quiet?');

      person.roles.add(muterole);
      message.channel.send(`@${person.id} has been muted for ${ms(ms(time))}`);

      setTimeout(function () {
        person.roles.remove(muterole);
      }, ms(time));
  }
});

我的错误:

(node:2780) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
user_id: Value "<@!402128830472650752>" is not snowflake.

1 个答案:

答案 0 :(得分:0)

在这一行:

const express = require('express');
const app = express();
const server = require('http').Server(app);

app.get('/',(req, res) => {
    res.sendFile(__dirname + '/client/index.html');
})

app.use('./', express.static(__dirname + '/client'));
app.use('../', express.static(__dirname + '/client'));

const port = process.env.PORT || 2000;

server.listen(port);

使用const person = message.guild.member( message.mentions.users.first() && message.guild.members.fetch(args[1]) ); 代替message.guild.members.cache.get