有人可以告诉我我做错了什么吗?
/*
bot.on('message', message =>{
if(message.author.bot) return;
const TicketToolEmbed = new Discord.MessageEmbed()
.setTitle("Creat a support Ticket")
.setDescription("React to this message to open a support ticket with the Server Administrators")
.setColor("#B900FF")
.setTimestamp()
.setFooter("Ticket Bot System")
message.channel.send(TicketToolEmbed)
.then(message => message.react('✅'))
.catch(err => console.log(err));
}); */
bot.on('raw', async payload => {
let eventname = payload.t;
if (eventname === 'MESSAGE_REACTION_ADD') {
let msgId = payload.d.message_id;
if (msgId === '712016328189411348') {
let channelId = payload.d.channelId;
let channel = Client.channels.get(channelId);
if (channel) {
if (channel.message.has(msgId))
return;
else {
try {
let msg = await channel.fetchMessage(msgId);
let reaction = msg.reaction.get('✅');
let user = Client.user.get(payload.d.user_id);
Client.emit('messageReactionAss', reaction, user);
}
catch (ex) {
console.log(ex);
return;
}
}
}
}
}
});
bot.on('messageReactionAdd', (reaction, user) => {
if(reaction.emoji.name === '✅') {
console.log("Creating ticket...");
}
else {
console.log("Wrong emoji");
}
});
控制台:
(node:11924) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined
at Client.<anonymous> (C:\Users\sande\Desktop\discbot\index.js:65:43)
at Client.emit (events.js:310:20)
at WebSocketShard.onMessage (C:\Users\sande\Desktop\discbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:287:27)
at WebSocket.onMessage (C:\Users\sande\Desktop\discbot\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:310:20)
at Receiver.receiverOnMessage (C:\Users\sande\Desktop\discbot\node_modules\ws\lib\websocket.js:800:20)
at Receiver.emit (events.js:310:20)
at Receiver.dataMessage (C:\Users\sande\Desktop\discbot\node_modules\ws\lib\receiver.js:436:14)
at Receiver.getData (C:\Users\sande\Desktop\discbot\node_modules\ws\lib\receiver.js:366:17)
at Receiver.startLoop (C:\Users\sande\Desktop\discbot\node_modules\ws\lib\receiver.js:142:22)
(节点:11924)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。该错误是由于在没有catch块的情况下抛出异步函数而引起的,或者是由于拒绝了未经.catch()处理的诺言而引起的。要在未处理的承诺拒绝时终止节点进程,请使用CLI标志--unhandled-rejections=strict
(请参见https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。 (拒绝ID:1)
(节点:11924)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝。将来,未处理的承诺拒绝将以非零退出代码终止Node.js进程。
答案 0 :(得分:1)
我相信您在所有代码示例中都使用了Client
而不是bot
。
尝试以下操作:
bot.on('raw', async payload => {
let eventname = payload.t;
if (eventname === 'MESSAGE_REACTION_ADD') {
let msgId = payload.d.message_id;
if (msgId === '712016328189411348') {
let channelId = payload.d.channelId;
let channel = bot.channels.get(channelId);
if (channel) {
if (channel.message.has(msgId))
return;
else {
try {
let msg = await channel.fetchMessage(msgId);
let reaction = msg.reaction.get('✅');
let user = bot.user.get(payload.d.user_id);
bot.emit('messageReactionAdd', reaction, user); // Also corrected "messageReactionAss" to "messageReactionAdd".
}
catch (ex) {
console.log(ex);
return;
}
}
}
}
}
});
bot.on('messageReactionAdd', (reaction, user) => {
if(reaction.emoji.name === '✅') {
console.log("Creating ticket...");
}
else {
console.log("Wrong emoji");
}
});