当我打字的时候,我需要有人的帮助!ticket它给了我一个错误,代码和错误,我试过了,我不能让它工作,所以我来这里询问,请让我知道你是否可以帮助我。这可能是一个非常简单的问题,我真的很难理解它。我也不能让表情符号工作,如果你能帮助它,那就太好了
const Discord = require("discord.js")
const ms = require('ms');
module.exports = {
name: 'ticket',
usage: '%ticket <reason>',
description: 'makes a ticket',
async execute(client, message, args, cmd, discord) {
const channel = await message.guild.channels.create(`ticket: ${message.user.tag}`);
channel.setParent('855596395783127081');
channel.updateOverwrite(message.guild.id, {
SEND_MESSAGE: false,
VEIW_CHANNEL: false
})
channel.updateOverwrite(message.auther, {
SEND_MESSAGE: true,
VEIW_CHANNEL: true
})
const reactionMessage = await channel.send(`Thank you for contacting support! A staff member will be with you as soon as possible`);
try {
await reactionMessage.react(":lock:");
await reactionMessage.react(":no_entry:");
} catch (err) {
channel.send(`Error Sending Emojis`);
throw err;
}
const collector = reactionMessage.createReactionCollector((reaction, user) =>
message.guild.member.cache.find((member) => member.id === userid).hasPermission('ADMINISTRATOR'), { dispose: true }
);
collector.on('collect', (reaction, user) => {
switch (reaction.emoji.name) {
case ":lock:":
channel.updateOverwrite(message.auther, { SEND_MESSAGE: false });
break;
case ":no_entry:":
channel.send('Deleteing ticket in 5 seconds');
setTimeout(() => channel.delete(), 5000);
break;
}
});
message.channel.send(`We will be right withyou! ${channel}`).then((msg) => {
setTimeout(() => msg.delete(), 7000)
setTimeout(() => message.delete(), 7000)
})
}
}
错误如下所示
PS C:\Users\lolzy\OneDrive\Desktop\discordbot> node .
Cbs slave is online!
(node:19284) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tag' of undefined
at Object.execute (C:\Users\lolzy\OneDrive\Desktop\discordbot\commands\ticket.js:10:85)
at module.exports (C:\Users\lolzy\OneDrive\Desktop\discordbot\events\guild\message.js:10:26)
at Client.emit (events.js:376:20)
at MessageCreateAction.handle (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:376:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19284) 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: 1)
(node:19284) [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.
发布于 2021-06-19 01:46:10
在Message
对象中没有调用.user
的属性,它应该是.author
,即返回User
对象,文档here
所以正确的代码应该是
const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`);
https://stackoverflow.com/questions/68042735
复制相似问题