【问题标题】:Ban discord v13 send dm禁止不和谐 v13 送dm
【发布时间】:2022-01-23 07:28:32
【问题描述】:

晚上好,我在 v13 中制作了我的机器人,但在禁止我想要的人之前,我无法让我的机器人在 dm 中发送消息,但没有成功,所以我来寻求帮助,如果你想要,这里是代码。 :

const discord = module.require("discord.js");

module.exports = {
  name: "ban",
  category: "moderation",
  description: "Ban anyone with one shot whithout knowing anyone xD",
  usage: "ban <@user> <reason>",
  userPerms: ["BAN_MEMBERS"],
  botPerms: ["EMBED_LINKS", "BAN_MEMBERS"],
  run: async (client, message, args) => {
    let reason = args.slice(1).join(" ");
    if (!reason) reason = "Unspecified";

    const target = message.mentions.members.first() || message.guild.users.cache.get(args[0]);

    if (!target) {
      return message.channel.send(
        `**${message.author.username}**, Please mention the person who you want to ban.`
      );
    }

    if (target.id === message.author.id) {
      return message.channel.send(
        `**${message.author.username}**, You can not ban yourself!`
      );
    }
    if (target.id === message.guild.ownerId) {
      return message.channel.send("You cannot Ban The Server Owner");
    }

    let embed = new discord.MessageEmbed()
      .setTitle("Action : Ban")
      .setDescription(`Banned ${target} (${target.id})\nReason: ${reason}`)
      .setColor("#ff2050")
      .setThumbnail(target.avatarURL)
      .setFooter(`Banned by ${message.author.tag}`);

    await message.guild.bans.create(target, {
      reason: reason
    }).then(() => {
        message.channel.send({ embeds: [embed] });
      });
  },
};

【问题讨论】:

    标签: node.js discord discord.js bots


    【解决方案1】:

    可能是机器人无权禁止您尝试禁止的成员,因此未调用 .then 回调。

    要么在 promise 中使用 .catch() 回调,要么将方法放在 try{}catch{} 块中。

    使用.catch()

    await message.guild.bans.create(target, {
        reason: reason
    })
    .catch((e) => {
        console.log(`Error: ${e}`);
    })
    .then(() => {
        message.channel.send({
            embeds: [embed]
        })
    })
    

    使用 try/catch:

    try {
        await message.guild.bans.create(target, { reason: reason})
        .then(() => {
            message.channel.send({
                embeds: [embed]
            })
        })
    }
    catch (e) {
        console.log(`Error: ${e}`);
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 2018-07-21
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多