[英]Discord.js ticket bot with reaction
I am trying to make a ticket system, but there is a problem.我正在尝试制作票务系统,但是有一个问题。 I want to make it when somebody opens a ticket, wait until the ticket closes, and then let them react again.
我想在有人打开票时做到这一点,等到票关闭,然后让他们再次做出反应。 (cooldown)
(冷却)
Here is my code:这是我的代码:
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)
})
}
}
});
I'm not sure if there is a way to catch the id of the user who reacted "I'll put "${reaction.author.id}" as an example because I don't know how but if you know how then you can do it by changing the created channel name to:我不确定是否有办法捕获做出反应的用户的 id “我将把“${reaction.author.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' })
I'm not sure if there is a way to catch the id of the user who reacted "I'll put "${reaction.author.id}" as an example because I don't know how but if you know how then you can do it by changing the created channel name to:我不确定是否有办法捕获做出反应的用户的 id “我将把“${reaction.author.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'
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.