如果通道已存在,则发送消息



我正在研究一种票务系统。假设有人有一张名为ticket-$ {message.author.username}的票证,我怎样才能阻止该人制作另一张票?因为我尝试它的方式不起作用。

编辑:我现在添加了很多代码,这几乎是我的全部代码。我仍然收到这些更改的错误。

法典:

module.exports.run = async (bot, message, args) => {
message.delete();
const filter = (reaction, user) => ['🗒️', '👨‍💻', '🖥️', '🧐'].includes(reaction.emoji.name) && user.id === message.author.id;
var name = `ticket-${message.author.username}`
const category = message.guild.channels.cache.get('708800011160256582');
let supportRole = message.guild.roles.cache.get("708629895621640242");
let supportRole2 = message.guild.roles.cache.get("708628839659733032");
let chan = `ticket-${message.author.username}`;
if (message.guild.channels.cache.find(channel => channel.name === chan)) {
return message.channel.send("TEST")
} else {
message.guild.channels.create(name, {
parent: category,
topic: `📩 TICKET | ${message.author.username}`,
permissionOverwrites: [{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES'],
}, {
id: message.guild.id,
deny: ['VIEW_CHANNEL'],
}, {
id: supportRole,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
}, {
id: supportRole2,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
}]
})
}
}).then(async c => {
let orderEmbed = new Discord.MessageEmbed()
.setTitle("Choose one of the topics below.")
.setColor("#e05856")
.setDescription(`
🗒️ » **Make order.**
👨‍💻 » **Personal support.**
🖥️ » **Technical support (Personal)**
🧐 » **Something else.**
`)
.setTimestamp();

c.send(orderEmbed).then(async msg => {
await msg.react("🗒️");
await msg.react("👨‍💻");
await msg.react('🖥️');
await msg.react("🧐");
msg.awaitReactions(filter, {
max: 1,
time: 30000,
errors: ['time']
}).then(collected => {
const reaction = collected.first();
switch(reaction.emoji.name) {
case '🗒️':
c.send("test1");
break;
case '👨‍💻':
c.send("test2");
break;
case '🖥️':
c.send("test3");
break;
case '🧐':
c.send("test4");
break;
}
}).catch(collected => {
});
})

});
message.channel.send(`Hi ${message.author.username}! You have opened an order, view it in #${name.id}`).then(async msg => {

})
}
module.exports.help = {
name: "order"
}

我希望有人可以帮助我! :-(

你的代码应该可以工作,但既然你说它不起作用,那就这样做:

module.exports.run = async (bot, message, args) => {
message.delete();
const filter = (reaction, user) => ['🗒️', '👨‍💻', '🖥️', '🧐'].includes(reaction.emoji.name) && user.id === message.author.id;
var name = `ticket-${message.author.username}`
const category = message.guild.channels.cache.get('708800011160256582');
let supportRole = message.guild.roles.cache.get("708629895621640242");
let supportRole2 = message.guild.roles.cache.get("708628839659733032");
let chan = `ticket-${message.author.username}`;
if (message.guild.channels.cache.find(channel => channel.name === chan)) {
return message.channel.send("TEST")
} else {
message.guild.channels.create(name, {
parent: category,
topic: `📩 TICKET | ${message.author.username}`,
permissionOverwrites: [{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES'],
}, {
id: message.guild.id,
deny: ['VIEW_CHANNEL'],
}, {
id: supportRole,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
}, {
id: supportRole2,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
}]
})
.then(async c => {
let orderEmbed = new Discord.MessageEmbed()
.setTitle("Choose one of the topics below.")
.setColor("#e05856")
.setDescription(`
🗒️ » **Make order.**
👨‍💻 » **Personal support.**
🖥️ » **Technical support (Personal)**
🧐 » **Something else.**
`)
.setTimestamp();

c.send(orderEmbed).then(async msg => {
await msg.react("🗒️");
await msg.react("👨‍💻");
await msg.react('🖥️');
await msg.react("🧐");
msg.awaitReactions(filter, {
max: 1,
time: 30000,
errors: ['time']
}).then(collected => {
const reaction = collected.first();
switch (reaction.emoji.name) {
case '🗒️':
c.send("test1");
break;
case '👨‍💻':
c.send("test2");
break;
case '🖥️':
c.send("test3");
break;
case '🧐':
c.send("test4");
break;
}
}).catch(collected => {
});
})

});
message.channel.send(`Hi ${message.author.username}! You have opened an order, view it in #${name.id}`).then(async msg => {

})
}
}
module.exports.help = {
name: "order"
}

最新更新