discord - 使用不和谐机器人向用户发送消息
问题描述
我想制作一个不和谐机器人,基本上如果一个人在不和谐服务器中键入命令,例如“!帮助”,它会向用户发送一个 dm,说你好你能描述你的问题,然后它等待那个人输入他的答案然后它会问另一个问题并再次等待用户回复然后机器人说完成我们的工作人员会帮助你。之后,工作人员可以查看用户对机器人说的话。你能给我一个代码吗^^^上面的东西你能帮忙吗??我很困惑请帮助它,将不胜感激......
解决方案
我不会通过 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;
})