我不断收到此错误,
[防崩溃] | [UncaughtExceptionMonitor_Logs] | [开始] : =============== 未捕获的异常监视器:TypeError:无法读取未定义的属性(读取“GuildText”) 异常来源:uncaughtException [防崩溃] | [UncaughtExceptionMonitor_Logs] | [完] : =============== [防崩溃] | [UncaughtException_Logs] | [开始] : =============== 未捕获的异常:TypeError:无法读取未定义的属性(读取“GuildText”) 异常来源:uncaughtException [防崩溃] | [UncaughtException_Logs] | [完] : ===============
const { SlashCommandBuilder } = require('@discordjs/builders');
const { ChannelType } = require('discord.js'); // Ensure you are importing this correctly
const fs = require('fs');
const jailedUsersPath = './src/jailedUsers.json';
// Load jailed users from the file
function loadJailedUsers() {
return fs.existsSync(jailedUsersPath) ? JSON.parse(fs.readFileSync(jailedUsersPath)) : {};
}
function saveJailedUser(userId, guildId, roles) {
const jailedUsers = loadJailedUsers();
jailedUsers[userId] = { guildId, roles };
fs.writeFileSync(jailedUsersPath, JSON.stringify(jailedUsers, null, 4));
}
module.exports = {
data: new SlashCommandBuilder()
.setName('jail')
.setDescription('Jail a member')
.addUserOption(option =>
option.setName('user')
.setDescription('The user to jail')
.setRequired(true)),
async execute(interaction) {
const member = interaction.options.getMember('user');
// Ensure the jail system has been set up
const { jailRole, jailCategory, accessRole } = interaction.client.jailSetup || {};
if (!jailRole || !jailCategory || !accessRole) {
return interaction.reply({
content: 'Jail system is not set up yet. Please run `/jail-setup` first.',
ephemeral: true,
});
}
try {
// Save current roles
const memberRoles = member.roles.cache.map(role => role.id);
saveJailedUser(member.id, interaction.guild.id, memberRoles);
// Assign jail role to the member
await member.roles.set([jailRole]);
// Create the jail channel
const jailChannel = await interaction.guild.channels.create({
name: `${member.user.username}-jail`,
type: ChannelType.message.GuildText, // Ensure you are using the correct type reference
parent: jailCategory, // Category ID
permissionOverwrites: [
{
id: member.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
},
{
id: interaction.guild.id,
deny: ['VIEW_CHANNEL'], // Deny everyone else
},
{
id: accessRole,
allow: ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY'],
deny: ['SEND_MESSAGES'], // Allow access to see but not send messages
},
],
});
await jailChannel.send(`${member} has been jailed. Welcome to jail!`);
await interaction.reply({ content: `${member.user.username} has been jailed.`, ephemeral: true });
} catch (error) {
console.error('Error jailing user:', error);
await interaction.reply({ content: 'An error occurred while trying to jail the user.', ephemeral: true });
}
},
};
发生这种情况是因为 ChannelType 没有
message
属性。不同版本的GuildText
对discordjs
的引用方式有所不同。检查您从 package.json 安装的 discordjs
版本,并使用适当的属性访问 GuildText。
版本 | 财产 | 修改线路 |
---|---|---|
v14 |
|
|
v13 |
|
|
v12 |
|
|
来源: