我正在這樣做,所以如果成員說 ~new,它會為他制作一張新票,但問題是,頻道名稱必須輸入唯一編號,例如 t-1 然后是 t-2 等...
但它只堅持使用“t-1”,需要明確的是,我使用的是命令處理程式。
這是我的代碼:
module.exports = {
name: 'new',
category: 'Ticket',
description: 'Creates a new ticket.',
aliases: ['newticket'],
usage: 'new',
userperms: [],
botperms: [],
run: async (client, message, args) => {
let ticketCounter = 1;
const userTickets = new Map()
if(userTickets.has(message.author.tag)) {
return message.channel.send('<@' message.author.id '> you already have a ticket, please close your existing ticket first before opening a new one!').then(m => m.delete({timeout: 3000}));
}
message.guild.channels.create(`t-${ticketCounter}`, {
permissionOverwrites: [
{
id: message.author.id,
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
},
{
id: "916785912267034674",
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
},
{
id: message.guild.roles.everyone,
deny: ['VIEW_CHANNEL'],
},
],
type: 'text',
}).then(async channel => {
channel.setParent('916778691672031293');
userTickets.set(message.author.id, ticketCounter );
message.channel.send(`<@` message.author.id `>, you have successfully created a ticket! Please click on ${channel} to view your ticket.`).then(m => m.delete({timeout: 3000}));
channel.send(`Hi <@` message.author.id `>, welcome to your ticket! Please be patient, we will be with you shortly.`);
const logchannel = message.guild.channels.cache.find(channel => channel.name === 'test');
if(logchannel) {
logchannel.send(`Ticket-${ticketCounter} created. Click the following to veiw <#${channel.id}>`);
}
});
}
}
謝謝!
uj5u.com熱心網友回復:
使用<Map>.size而不是增量器,因為代碼在每個命令后重新執行,計數器每次都將設定為 1。
if(!client.userTickets) client.userTickets = new Map();
client.userTickets.set(message.author.id, client.userTickets.size 1);
message.guild.channels.create(`t-${client.userTickets.size 1}`, { ... });
您的代碼示例:
module.exports = {
name: 'new',
category: 'Ticket',
description: 'Creates a new ticket.',
aliases: ['newticket'],
usage: 'new',
userperms: [],
botperms: [],
run: async (client, message, args) => {
if(!client.userTickets) client.userTickets = new Map()
if(client.userTickets.has(message.author.id)) {
return message.channel.send('<@' message.author.id '> you already have a ticket, please close your existing ticket first before opening a new one!').then(m => m.delete({timeout: 3000}));
}
message.guild.channels.create(`t-${client.userTickets.size 1}`, {
permissionOverwrites: [
{
id: message.author.id,
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
},
{
id: "916785912267034674",
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
},
{
id: message.guild.roles.everyone,
deny: ['VIEW_CHANNEL'],
},
],
type: 'text',
}).then(async channel => {
channel.setParent('916778691672031293');
client.userTickets.set(message.author.id, client.userTickets.size 1);
message.channel.send(`<@` message.author.id `>, you have successfully created a ticket! Please click on ${channel} to view your ticket.`).then(m => m.delete({timeout: 3000}));
channel.send(`Hi <@` message.author.id `>, welcome to your ticket! Please be patient, we will be with you shortly.`);
const logchannel = message.guild.channels.cache.find(channel => channel.name === 'test');
if(logchannel) {
logchannel.send(`Ticket-${client.userTickets.size} created. Click the following to veiw <#${channel.id}>`);
}
});
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/379286.html
上一篇:將一個模式的值推入另一個模式
