簡體   English   中英

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

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

當我制作我的 discord 機器人時,我遇到了另一個問題。 現在我正在制定一個命令,應該 DM 機器人命令頻道中提到的人。 但我無法讓它工作。 我嘗試了很多東西,但它們似乎不起作用。 如果有人可以幫助我,我們將不勝感激這是我的 DM 命令代碼:

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

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

這是我在主文件中的代碼:

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

也許您需要先獲取用戶:

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個可能的原因,我的第一個猜測是你只能DM成員,而不是用戶

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

我的另一個猜測是,您嘗試 DM 的人不允許來自陌生人的 DM。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM