我正在尝试制作一个具有5个不同主题的门票系统,供人们用来制作门票,但我的大部分代码都写下来了,但是当机器人试图获取表情符号的集合时,我得到了错误提示:>
(node:43144) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emoji' of undefined
at C:\Users\nalfo\OneDrive\Desktop\Discord Bot\NetSync Beta\commands\ticket\ticket-create.js:171:39
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:43144) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)
(node:43144) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我也尝试只用表情符号名称和东西替换实际的表情符号。 这是我当前正在使用的代码:
const Discord = require('discord.js');
const db = require('quick.db');
const ms = require("parse-ms");
const randomstring = require("randomstring");
module.exports.run = async (bot, message, args) => {
if (message.deletable) message.delete();
let permembed = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`An error occured: I don't have permission to manage channels.`)
.setTimestamp()
.setFooter(`© NetSync by Towncraft Developers`);
if(!message.guild.me.hasPermission('MANAGE_CHANNELS')) return message.channel.send(permembed).then(msg => { msg.delete(10000) });
let user2 = message.author;
let timeout = 300;
let daily = await db.fetch(`ticketcooldown_${message.guild.id}_${message.author.id}`);
if (daily !== null && timeout - (Date.now() - daily) > 0) {
let time = ms(timeout - (Date.now() - daily));
**Embeds (Not Needed)**
let topic1 = db.fetch(`${message.guild.id}-topic1`)
let topic2 = db.fetch(`${message.guild.id}-topic2`)
let topic3 = db.fetch(`${message.guild.id}-topic3`)
let topic4 = db.fetch(`${message.guild.id}-topic4`)
let topic5 = db.fetch(`${message.guild.id}-topic5`)
if(topic1 == null) topic1 = 'General Issues';
if(topic2 == null) topic2 = 'Discord Issues';
if(topic3 == null) topic3 = 'Server Issues';
if(topic4 == null) topic4 = 'Submit a Report';
if(topic5 == null) topic5 = 'Other';
db.set(`${message.guild.id}_${message.author.id}-ticketnumber`, numbers)
db.add(`${message.guild.id}-ticketcount`, 1)
db.set(`${message.guild.id}_${message.author.id}-ticketopener`, message.author.username)
db.set(`${message.guild.id}_${message.author.id}-ticketopener2`, message.author.username)
db.set(`${message.guild.id}_${message.channel.id}-ticketopener3`, message.author.id)
let user2 = db.fetch(`${message.guild.id}_${message.author.id}-ticketopener2`)
console.log(user2)
let ticketcount = db.fetch(`${message.guild.id}-ticketcount`)
**More Embeds (Not Needed)**
let msg = await message.channel.send(input)
await msg.react("1️⃣")// 1️⃣2️⃣3️⃣4️⃣5️⃣
await msg.react("2️⃣")
await msg.react("3️⃣")
await msg.react("4️⃣")
await msg.react("5️⃣")
const filter = (reaction, user) => ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣'].includes(reaction.emoji.name) && user.id === message.author.id;
msg.awaitReactions(filter, {
max: 1,
time: 10000
}).then(collected => {
const reaction = collected.first();
switch (reaction.emoji.name) {
case '1️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic1)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend1)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed1)
message.channel.send(authorsend)
msg.delete()
});
break;
case '2️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic2)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend2)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed2)
message.channel.send(authorsend)
msg.delete()
});
break;
case '3️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic3)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend3)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed3)
message.channel.send(authorsend)
msg.delete()
});
break;
case '4️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic4)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend4)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed4)
message.channel.send(authorsend)
msg.delete()
});
break;
case '5️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic5)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend5)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed5)
message.channel.send(authorsend)
msg.delete()
});
break;
case '❌':
db.subtract(`${message.guild.id}-ticketcount`, 1)
msg.delete()
return message.channel.send(cancelembed)
}
})
db.set(`ticketcooldown_${message.guild.id}_${message.author.id}`, Date.now())
}}
module.exports.config = {
name: "ticket-create",
description: "Creates a new support ticket.",
usage: "!ticket-create (topic)",
accessableby: "Staff",
aliases: ["ticket-open", "ticket-new"]
}
第171行是:switch (reaction.emoji.name) {
更新的代码:
let msg = await message.channel.send(input)
await msg.react("1️⃣")// 1️⃣2️⃣3️⃣4️⃣5️⃣
await msg.react("2️⃣")
await msg.react("3️⃣")
await msg.react("4️⃣")
await msg.react("5️⃣")
const filter = (reaction, user) => ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣'].includes(reaction.emoji.name) && user.id === message.author.id;
msg.awaitReactions(filter, { time: 10000, errors: ["time"], max: 1 }).then(collected => { //Changed this to the new stuff
const reaction = collected.first();
switch (reaction.emoji.name) {
case '1️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic1)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend1)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed1)
message.channel.send(authorsend)
msg.delete()
});
break;
case '2️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic2)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend2)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed2)
message.channel.send(authorsend)
msg.delete()
});
break;
case '3️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic3)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend3)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed3)
message.channel.send(authorsend)
msg.delete()
});
break;
case '4️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic4)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend4)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed4)
message.channel.send(authorsend)
msg.delete()
});
break;
case '5️⃣':
db.set(`${message.guild.id}_${message.author.id}-ticketreason`, topic5)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find(r => r.name === '@everyone'), {
'VIEW_CHANNEL': false
})
chan.overwritePermissions(message.guild.roles.find(r => r.name === 'Staff'), {
'VIEW_CHANNEL': true
})
chan.overwritePermissions(message.author.id, {'VIEW_CHANNEL': true, 'SEND_MESSAGES': true, 'MENTION_EVERYONE': false})
let category = message.guild.channels.find(c => c.name == "⊱━≺ OPEN TICKETS ≻━━━━⊰" && c.type == "category");
if(!category) return message.channel.send(categorysend)
chan.setParent(category.id)
chan.send(channelsend5)
chan.setTopic(`Support Ticket ${numbers}`)
db.set(`${message.guild.id}_${message.author.id}-channelID`, chan.id)
let authorsend = new Discord.RichEmbed()
.setColor('#e64b0e')
.setDescription(`Ticket Created, #${chan.name}`)
let logchannel = message.guild.channels.find(cl => cl.name == "ticket-logs" && cl.type == "text")
logchannel.send(logchannelembed5)
message.channel.send(authorsend)
msg.delete()
});
break;
case '❌':
db.subtract(`${message.guild.id}-ticketcount`, 1)
msg.delete()
return message.channel.send(cancelembed)
}
}).catch(collected => {
msg.delete()
return message.channel.send(timeoutembed).then(msg => { msg.delete(10000) })
})
db.set(`ticketcooldown_${message.guild.id}_${message.author.id}`, Date.now())
}}
有什么想法吗?非常感谢。
答案 0 :(得分:2)
您有10秒的时间限制,但您没有定义时间不足就是错误
因此将选项更改为此
{ time: 10000, errors: ["time"], max: 1 }
如果您未将其定义为错误,则它将转到.then块,然后在then块中,您认为行代码有反应
const reaction = collected.first();
如果您选择这条路线,则需要添加一个catch
块
另一种选择是检查是否定义了反应,如果没有返回。