0

所以今天我试图通过 ping 让机器人 DM 成为特定的人,例如:!dm @potato hello

通过使用这个:

if (message.content.startsWith(prefix + 'dm')) {

        let args = message.content.split(" ")[2];
        let user = message.mentions.users.first()

        if (!user) return message.channel.send("**Please mention a user**")
        
 if (!message.member.roles.cache.has('814454313438806016')) {
            return message.channel.send('You do not have the permissions to use this command.')
        }
        if (!args[0])
            return message.reply("Nothing to say?").then(m => m.delete(5000));

        if (args[0].toLowerCase() === "embed") {
            const embed = new MessageEmbed()
                .setDescription(args.slice(1).join(" "))
                .setTimestamp()
                .setColor('WHITE');

            message.channel.send(embed);
        } else {
            message.channel.send('**Done**')
            user.send(args.join(" "));
        }
}

和SMH,它不起作用,我希望你们能帮助我

控制台链接截图:https ://prnt.sc/10kzxie

4

1 回答 1

0

Tbh,您的代码中没有很多错误,只是有点问题。使用以下,如果还有问题,请评论!

  if (message.content.startsWith(prefix + 'dm')) {
    let args = message.content.slice(prefix.length).split(/ +/g);
    let member = message.mentions.members.first()
    if (!member) return message.channel.send("**Please mention a member**")

    if (!message.member.roles.cache.has('814454313438806016')) {
      return message.channel.send('You do not have the permissions to use this command.')
    }
    if (!args[0]){
      return message.reply("Nothing to say?").then(m => m.delete(5000));
    }

    if (args[0].toLowerCase() === "embed") {
      const embed = new MessageEmbed()
      .setDescription(args.slice(2).join(" "))
      .setTimestamp()
      .setColor('WHITE');
      message.channel.send('**Done**')
      member.send(embed);
    } else {
      message.channel.send('**Done**')
      member.send(args.splice(1).join(" "));
    }
  }
于 2021-03-14T05:50:59.830 回答