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