使用Discord机器人向用户发送消息

时间:2020-07-23 05:28:31

标签: discord discord.js

我想制作一个将dm发送给用户的discord机器人 基本上,如果有人在不和谐的服务器中键入命令,例如“!help” 它会向用户发送dm消息,问好,您能描述一下您的问题吗,然后等待该人员键入答案,然后再询问另一个问题,然后再次等待用户答复,然后机器人说我们的工作人员会为您提供帮助。 之后,工作人员可以查看用户对机器人的发言。 您能为我上面的事情给这个^^^一个代码吗 您能帮忙吗?我很困惑,请帮助...

1 个答案:

答案 0 :(得分:0)

我不会通过DM进行操作,而是在行会中创建一个私人频道。 示例:

    //returns if the channel id in which the help command was executed doesnt match the ID.
    if (message.channel.id !== ("Ticket creation channel ID")) {
        message.delete();
        message.author.send("You need to execute this command in #tickets!");
        return;
    }
    //Creates an embed to tell the user in the ticket channel what to do
    const ticketEmbed = new MessageEmbed()
        .setColor("0x7a0000")
        .setAuthor(`Hello, ${message.author.username},`);
        .setDescription("Please describe your problem so staff can help you!")

    //Creates a text channel that allows the creator of the ticket to view the channel other than "normal" members
    message.guild.channels.create(`ticket-${message.author.username}`, {
        type: "text",
        permissionOverwrites: [
            {
                id: "Default role ID",
                deny: ["VIEW_CHANNEL"],
            },
            {
                id: message.author.id,
                allow: ["SEND_MESSAGES"],
            },
            {
                id: "Staff role ID",
                allow: ["SEND_MESSAGES", "MANAGE_CHANNELS"]
            }
        ]
    }).then(result => {
        //Sets the slow mode to 10 seconds
        result.setRateLimitPerUser(10)
        message.channel.send(`Ticket created. Please describe your problem in <#${result.id}> so staff can help you.`)
        message.guild.channels.cache.get(result.id).send(ticketEmbed)
        //Sends "(Message author) just created a ticket in (mentioned ticket channel) and reacts with "?"
        message.guild.channels.cache.get("Ticket notifier channel ID").send(`${message.author.tag} just created a ticket in <#${result.id}>`).then(r => r.react("?"))
        return;
        })