您如何从 dm 获得用户响应? (Discord Node js bot)

时间:2021-04-07 01:45:37

标签: javascript node.js discord

自从上一个发生了一些事情后,我就开始为我的 Discord 服务器制作一个机器人。 我一直在尝试让机器人获取用户(它是 DMS)的输入,但不知道如何做到这一点。 下面是我到目前为止所做的

const Discord = require('discord.js');

const client = new Discord.Client();

const prefix = 'a!';

const Commands = '!help !version !post';

const MarketplaceCommnads = "Looking for Devs For Hire Looking for Creations Sell Creations"

const Version = '1.0.0';

client.once('ready', () => {
    console.log('Bot is online!');
});

const helpEmbed = new Discord.MessageEmbed()
    .setTitle('Help')
    .setColor('#ff0000')
    .addField('Command List', Commands)
const postEmbed = new Discord.MessageEmbed()
    .setTitle("Post")
    .setColor("#ff0000")
    .addField('The bot has dmed you')
const dmEmbed = new Discord.MessageEmbed()
    .setTitle("New Post")
    .setColor("#ff0000")
    .addField("Create a new post", MarketplaceCommnads)
const lookingfordevsEmbed = new Discord.MessageEmbed()
    .setTitle("Looking for Devs")
    .setColor("#ff0000")
    .addField("Post everything here (What you're looking for, payment, etc): ")
const versionEmbed = new Discord.MessageEmbed()
    .setTitle('Version')
    .setColor('#ff0000')
    .addField('Version', Version)
    .setColor('#ff0000')


client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot ) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if (command === 'help'){
        message.channel.send(helpEmbed);
    }
    if (command === 'version'){
        message.channel.send(versionEmbed);
    }
    if (command === 'post'){
        message.channel.send(postEmbed);
        message.author.send(dmEmbed);
        const Message = Response()
        if (Message === 'Looking for Devs'){
            message.author.send(lookingfordevsEmbed);
        }
    }
});

我以前使用过 Node JS,但这是我第一次创建机器人,所以我正在尝试了解所有这些是如何工作的,所以这似乎是一个明显的错误。我在提出这个问题之前尝试过的解决方案:Youtube and Googling

1 个答案:

答案 0 :(得分:0)

因此,您可以首先使用 Message#channel 检查它是否是 DM 并查看它是否是 DMChannel,并获取他们的用户,您可以执行 Message#author 返回用户。 这是我谈到的每件事的文档

<块引用>

消息:https://discord.js.org/#/docs/main/stable/class/Message

DM 频道:https://discord.js.org/#/docs/main/stable/class/DMChannel

用户:https://discord.js.org/#/docs/main/stable/class/User

希望这有帮助!