简体   繁体   English

dm function 不适用于 discord 机器人

[英]dm function is not working on discord bot

I'm trying to make a DM command in a Discord Bot based on JavaScript but my code is throwing an error.我正在尝试在基于 JavaScript 的 Discord Bot 中发出 DM 命令,但我的代码抛出错误。

function dm(message, args) {
    let dUser = message.guild.member(message.mentions.users.first())
        || message.guild.members.get(args[0]);

    if (!dUser) return message.channel.send(geengebruiker);

    if (!message.member.hasPermission('MANAGE_GUILD'))
        return message.channel,send(geenstaff);

    let dMessage = args.join(' ').slice(22);
    if (dMessage.length < 1) return message.channel.send(geenbericht);
      
    dUser.send(`${dUser}`, staffdm, `${dMessage}`);
      
    message.author.send(
        `${message.author}`, senddm, `${dUser}`
    );
}

The error I get: https://prnt.sc/10rxzct我得到的错误: https://prnt.sc/10rxzct

By placing commas between your strings when you call TextChannel#Send , it actually means that you're passing them as different parameters to the method.通过在调用TextChannel#Send时在字符串之间放置逗号,这实际上意味着您将它们作为不同的参数传递给方法。 What you want to do is combine them into a single string and simply call it as TextChannel.send("your string");您想要做的是将它们组合成一个字符串,并简单地将其称为TextChannel.send("your string"); . .

Examples:例子:

dUser.send(`${dUser} ${staffdm} ${dMessage}`);
message.author.send(`${message.author} ${senddm} ${dUser}`);

You also have a syntax error:您还有一个语法错误:

return message.channel,send(geenstaff);

should be应该

return message.channel.send(geenstaff);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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