【发布时间】:2021-09-14 15:16:23
【问题描述】:
我正在我的 discord 机器人中尝试此 JavaScript 票证代码,但错误 TypeError: Cannot read property 'guild' of undefined 不断出现。我不明白为什么。有人可以指导我正确的方向吗?
module.exports = {
name: "ticket",
aliases: [],
permissions: [],
description: "Open a ticket!",
async execute(message, args, cmd, client, discord) {
const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`);
channel.setParent("820276801652916270");
channel.updateOverwrite(message.guild.id, {
SEND_MESSAGE: false,
VIEW_CHANNEL: false,
});
channel.updateOverwrite(message.author, {
SEND_MESSAGE: true,
VIEW_CHANNEL: true,
});
const reactionMessage = await channel.send("Thank you for contacting support!");
try {
await reactionMessage.react("????");
await reactionMessage.react("⛔");
} catch (err) {
channel.send("Error sending emojis!");
throw err;
}
const collector = reactionMessage.createReactionCollector(
(reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission("ADMINISTRATOR"),
{ dispose: true }
);
collector.on("collect", (reaction, user) => {
switch (reaction.emoji.name) {
case "????":
channel.updateOverwrite(message.author, { SEND_MESSAGES: false });
break;
case "⛔":
channel.send("Deleting this channel in 5 seconds!");
setTimeout(() => channel.delete(), 5000);
break;
}
});
message.channel
.send(`We will be right with you! ${channel}`)
.then((msg) => {
setTimeout(() => msg.delete(), 7000);
setTimeout(() => message.delete(), 3000);
})
.catch((err) => {
throw err;
});
},
}
【问题讨论】:
-
执行文件时好像没有定义
message。你能给我们提供执行这个文件的代码吗? -
是的...你是指其中一个部分吗? if(command === 'ticket'){ client.commands.get('ticket').execute(message.args); } }) const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')) for(const file of commandFiles){ const command = require(
./commands/${file}) ; client.commands.set(command.name, command); } async execute(message, args, cmd, client, discord) {
标签: discord.js