简体   繁体   English

discord.js DM 命令未直接消息提及用户

[英]discord.js DM command not direct messaging mentioned users

When I was making my discord bot, I came to another problem.当我制作我的 discord 机器人时,我遇到了另一个问题。 Now I am making a command that should DM a person that is mentioned in bot commands channel.现在我正在制定一个命令,应该 DM 机器人命令频道中提到的人。 But I can't make it to work.但我无法让它工作。 I tried a lot of things but they don't seem to work.我尝试了很多东西,但它们似乎不起作用。 If someone can help me that help will be really appreciated Here is my code for a DM command:如果有人可以帮助我,我们将不胜感激这是我的 DM 命令代码:

module.exports = {
    name:'dm',
    description: 'dm mentioned user',
    execute(message, args){
        const user = message.mentions.users.first()

        user.send('test command');
        
        
        
    }
}

and this is my code in main file:这是我在主文件中的代码:

if(command === 'dm'){
        client.commands.get('dm').execute(message, args, Discord, client);
    }

Maybe you need to fetch the user first:也许您需要先获取用户:

module.exports = {
  name: 'dm',
  description: 'dm mentioned user',
  async execute(message, args) {
    const user = await message.mentions.users.first().fetch();
    const channel = await user.createDM();

    channel.send('test command');
  },
};

2 possible reasons, my first guess is that you can only DM members, not users 2个可能的原因,我的第一个猜测是你只能DM成员,而不是用户

const user = message.mentions.users.first()
user.send('test command');

My other guess is that the person you're trying to DM does not allow DMs from strangers.我的另一个猜测是,您尝试 DM 的人不允许来自陌生人的 DM。

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

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