【问题标题】:Sending a message to a user using a discord bot使用不和谐机器人向用户发送消息
【发布时间】:2020-11-12 18:39:42
【问题描述】:

我想制作一个不和谐的机器人,将 dm 发送给用户 基本上,如果一个人在不和谐服务器中键入命令,例如“!帮助” 它会向用户发送一条 dm,说你好,你能描述一下你的问题,然后它等待这个人输入他的答案,然后它会问另一个问题,然后再次等待用户回复,然后机器人说完成,我们的工作人员会帮助你。 之后,工作人员可以查看用户对机器人说的话。 你能给我一个代码吗^^^上面的东西 你能帮忙吗?我很困惑请帮助它,将不胜感激......

【问题讨论】:

  • 您似乎被严重否决了,因为您要求人们为您编写代码。 Stack Overflow 旨在帮助解决问题,而不是编写代码。请阅读How do I ask a good question?

标签: discord discord.js


【解决方案1】:

我不会通过 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;
        })

【讨论】:

    猜你喜欢
    • 2021-04-03
    • 2022-01-08
    • 1970-01-01
    • 2020-05-31
    • 2022-11-02
    • 2020-07-28
    • 2019-12-10
    • 2019-06-27
    • 1970-01-01
    相关资源
    最近更新 更多