【问题标题】:Discord.js ticket bot with reaction具有反应的 Discord.js 票务机器人
【发布时间】:2021-04-24 19:05:00
【问题描述】:

我正在尝试制作票务系统,但是出现了问题。我想在有人打开票时做到这一点,等到票关闭,然后让他们再次做出反应。 (冷却时间)

这是我的代码:

client.on('messageReactionAdd', async (reaction, user) => {
    if (user.partial) await user.fetch();
    if (reaction.partial) await reaction.fetch();
    if (reaction.message.partial) await reaction.message.fetch();
    if (user.bot) return; {
        let ticketid = await db.get(`tickets_${reaction.message.guild.id}`);
        if (!ticketid) return;
        if (reaction.message.id == ticketid && reaction.emoji.name == ':tickets:') {
            db.add(`ticketnumber_${reaction.message.guild.id}`, 1)
            let ticketnumber = await db.get(`ticketnumber_${reaction.message.guild.id}`)
            if (ticketnumber === null) ticketnumber = "1"
            reaction.users.remove(user);
            let CH = message.guild.channels.find(r => r.id == '770687676152020993');
            if (!CH) return;
            reaction.message.guild.channels.create(`ticket-${ticketnumber}`, {
                type: 'text', parent: CH, reason: 'Reaction Tickets System',
                permissionOverwrites: [
                    {
                        id: user.id,
                        allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
                    },
                    {
                        id: reaction.message.guild.roles.everyone,
                        deny: ["VIEW_CHANNEL"]
                    }
                ],
                type: 'text'
            }).then(async channel => {
                let data = {
                    channelid: channel.id
                }
                db.push(`tickets`, data).then(console.log)
                channel.send(`<@${user.id}>`).then(log => { db.set(`mention_${channel.id}`, log.id) })
                db.set(`ticketauthor_${channel.id}`, user.id)
                let icon = reaction.message.guild.iconURL()
                let ticketmsg = await channel.send(new Discord.MessageEmbed()
                    .setTitle(`${user.username} Ticket`)
                    .setDescription("We are going to contact you as soon\n Click the reaction to close the ticket:closed_lock_with_key:")
                    .setFooter(reaction.message.guild.name, icon)
                    .setTimestamp()
                );
                ticketmsg.react(':closed_lock_with_key:')
                console.log(`${ticketmsg.id}`)
                db.set(`closeticket_${channel.id}`, ticketmsg.id)
            })
        }
    }
});

【问题讨论】:

  • 请使用缩进使您的代码对其他人更具可读性。
  • 您好@Adob,请缩进您的代码,另外我建议您编写具体的错误和您打算执行的具体代码段,以及具体的错误,因为我们不在这种情况下,有足够的上下文真的很难帮助你。

标签: javascript node.js discord discord.js ticket-system


【解决方案1】:

我不确定是否有办法捕获响应“我将把“${reaction.author.id}”作为示例的用户的 id,因为我不知道如何,但如果你知道如何通过将创建的频道名称更改为:

const ch = message.guild.channels.cache.find(ch => ch.name.toLowerCase() === `ticket-${reaction.author.id}`)

if(ch) return

reaction.message.guild.channels.create(`ticket-${reaction.author.id}`, {
                type: 'text', parent: CH, reason: 'Reaction Tickets System',
                permissionOverwrites: [
                    {
                        id: user.id,
                        allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
                    },
                    {
                        id: reaction.message.guild.roles.everyone,
                        deny: ["VIEW_CHANNEL"]
                    }
                ],
                type: 'text'
            })

我不确定是否有办法捕获响应“我将把“${reaction.author.id}”作为示例的用户的 id,因为我不知道如何,但如果你知道如何通过将创建的频道名称更改为:

const example = message.guild.channels.cache.find(ch => ch.name.toLowerCase() === `ticket-${reaction.author.id}`)

if(example) return

reaction.message.guild.channels.create(`ticket-${reaction.author.id}`, {
                type: 'text', parent: CH, reason: 'Reaction Tickets System',
                permissionOverwrites: [
                    {
                        id: user.id,
                        allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
                    },
                    {
                        id: reaction.message.guild.roles.everyone,
                        deny: ["VIEW_CHANNEL"]
                    }
                ],
                type: 'text'
            })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2020-08-09
    • 2021-01-06
    • 2020-01-11
    • 2021-10-10
    • 2020-11-24
    • 2021-05-13
    • 2020-12-04
    相关资源
    最近更新 更多