Cgx
DIAdiscord.js - Imagine a bot
•Created by Cgx on 10/28/2023 in #djs-questions
permission | bitfield invalid
if (!permissions.has("VIEW_CHANNEL")) {
interaction.reply("Channel has to be viewable to everyone.");
return;
if (!permissions.has("VIEW_CHANNEL")) {
interaction.reply("Channel has to be viewable to everyone.");
return;
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: VIEW_CHANNEL.
at Function.resolve (/home/container/node_modules/discord.js/src/util/BitField.js:172:11)
at PermissionsBitField.has (/home/container/node_modules/discord.js/src/util/BitField.js:60:28)
at PermissionsBitField.has (/home/container/node_modules/discord.js/src/util/PermissionsBitField.js:92:82)
at Object.execute (/home/container/src/commands/setup.js:49:22)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'BitFieldInvalid'
}
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: VIEW_CHANNEL.
at Function.resolve (/home/container/node_modules/discord.js/src/util/BitField.js:172:11)
at PermissionsBitField.has (/home/container/node_modules/discord.js/src/util/BitField.js:60:28)
at PermissionsBitField.has (/home/container/node_modules/discord.js/src/util/PermissionsBitField.js:92:82)
at Object.execute (/home/container/src/commands/setup.js:49:22)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'BitFieldInvalid'
}
4 replies
DIAdiscord.js - Imagine a bot
•Created by Cgx on 9/4/2023 in #djs-questions
Permission system not working
Hello, I'm currently coding a steal command where you are able to add emojis. But the Permission system isnt working...
TypeError: interaction.client.permissionsIn is not a function
TypeError: interaction.client.permissionsIn is not a function
if (
!interaction.guild.me.permissions.has(
Permissions.FLAGS.MANAGE_EMOJIS
)
) {
return interaction.reply(
"I don't have permission to manage emojis in this server."
);
}
if (
!interaction.guild.me.permissions.has(
Permissions.FLAGS.MANAGE_EMOJIS
)
) {
return interaction.reply(
"I don't have permission to manage emojis in this server."
);
}
26 replies
DIAdiscord.js - Imagine a bot
•Created by Cgx on 7/24/2023 in #djs-questions
Cannot read properties of null (reading 'id')
Hey, so I have a code that worked everytime, but now not longer...
Version: 14.11.0
/home/container/src/commands/guesspic.js:42
if (activeRounds[channel.id]) {
^
TypeError: Cannot read properties of null (reading 'id')
at Object.execute (/home/container/src/commands/guesspic.js:42:30)
at module.exports (/home/container/src/events/interactionCreate.js:6:13)
at BoilerplateClient.emit (node:events:512:28)
at InteractionCreateAction.handle (/home/container/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/home/container/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:354:31)
at WebSocketManager.<anonymous> (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:238:12)
at WebSocketManager.emit (/home/container/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/home/container/node_modules/@discordjs/ws/dist/index.js:1103:51)
at WebSocketShard.emit (/home/container/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
/home/container/src/commands/guesspic.js:42
if (activeRounds[channel.id]) {
^
TypeError: Cannot read properties of null (reading 'id')
at Object.execute (/home/container/src/commands/guesspic.js:42:30)
at module.exports (/home/container/src/events/interactionCreate.js:6:13)
at BoilerplateClient.emit (node:events:512:28)
at InteractionCreateAction.handle (/home/container/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/home/container/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:354:31)
at WebSocketManager.<anonymous> (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:238:12)
at WebSocketManager.emit (/home/container/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/home/container/node_modules/@discordjs/ws/dist/index.js:1103:51)
at WebSocketShard.emit (/home/container/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
15 replies
DIAdiscord.js - Imagine a bot
•Created by Cgx on 7/22/2023 in #djs-questions
channel.isTextBased() is not a function
I have a ticket bot but by trying to open a ticket it gives me the following Error:
It looks like the error is at:
but i'm not sure how to fix it.
0|ticketer-backend | TypeError: channel.isTextBased is not a function
0|ticketer-backend | at InteractionCreateAction.handle (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/actions/InteractionCreate.js:46:33)
0|ticketer-backend | at module.exports [as INTERACTION_CREATE] (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
0|ticketer-backend | at WebSocketManager.handlePacket (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31)
0|ticketer-backend | at WebSocketShard.onPacket (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/websocket/WebSocketShard.js:481:22)
0|ticketer-backend | at WebSocketShard.onMessage (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/websocket/WebSocketShard.js:321:10)
0|ticketer-backend | at WebSocket.onMessage (/home/ticketer-backend-main/ticketer-backend-main/node_modules/ws/lib/event-target.js:199:18)
0|ticketer-backend | at WebSocket.emit (node:events:512:28)
0|ticketer-backend | at Receiver.receiverOnMessage (/home/ticketer-backend-main/ticketer-backend-main/node_modules/ws/lib/websocket.js:1178:20)
0|ticketer-backend | at Receiver.emit (node:events:512:28)
0|ticketer-backend | at Receiver.dataMessage (/home/ticketer-backend-main/ticketer-backend-main/node_modules/ws/lib/receiver.js:528:14)
0|ticketer-backend | Node.js v20.4.0
0|ticketer-backend | TypeError: channel.isTextBased is not a function
0|ticketer-backend | at InteractionCreateAction.handle (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/actions/InteractionCreate.js:46:33)
0|ticketer-backend | at module.exports [as INTERACTION_CREATE] (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
0|ticketer-backend | at WebSocketManager.handlePacket (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31)
0|ticketer-backend | at WebSocketShard.onPacket (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/websocket/WebSocketShard.js:481:22)
0|ticketer-backend | at WebSocketShard.onMessage (/home/ticketer-backend-main/ticketer-backend-main/node_modules/discord.js/src/client/websocket/WebSocketShard.js:321:10)
0|ticketer-backend | at WebSocket.onMessage (/home/ticketer-backend-main/ticketer-backend-main/node_modules/ws/lib/event-target.js:199:18)
0|ticketer-backend | at WebSocket.emit (node:events:512:28)
0|ticketer-backend | at Receiver.receiverOnMessage (/home/ticketer-backend-main/ticketer-backend-main/node_modules/ws/lib/websocket.js:1178:20)
0|ticketer-backend | at Receiver.emit (node:events:512:28)
0|ticketer-backend | at Receiver.dataMessage (/home/ticketer-backend-main/ticketer-backend-main/node_modules/ws/lib/receiver.js:528:14)
0|ticketer-backend | Node.js v20.4.0
case InteractionType.MessageComponent:
if (channel && !channel.isTextBased()) return;
case InteractionType.MessageComponent:
if (channel && !channel.isTextBased()) return;
13 replies
DIAdiscord.js - Imagine a bot
•Created by Cgx on 6/29/2023 in #djs-questions
Not finding an announcement channel
Hello, I dont know why, but it seems like it doesnt find the announcement channel.
const banGlobalChannelId = '1123739036394201188';
const banGlobalChannel = client.channels.cache.get(banGlobalChannelId);
if (banGlobalChannel && (banGlobalChannel.type === 'GUILD_TEXT' || banGlobalChannel.type === 'GUILD_ANNOUNCEMENT')) {
const filter = (interaction) => interaction.customId === 'ban_globally';
const collector = banGlobalChannel.createMessageComponentCollector({ filter, time: 60000 });
const banGlobalChannelId = '1123739036394201188';
const banGlobalChannel = client.channels.cache.get(banGlobalChannelId);
if (banGlobalChannel && (banGlobalChannel.type === 'GUILD_TEXT' || banGlobalChannel.type === 'GUILD_ANNOUNCEMENT')) {
const filter = (interaction) => interaction.customId === 'ban_globally';
const collector = banGlobalChannel.createMessageComponentCollector({ filter, time: 60000 });
12 replies
DIAdiscord.js - Imagine a bot
•Created by Cgx on 5/4/2023 in #djs-questions
props.run is not a function
18 replies
DIAdiscord.js - Imagine a bot
•Created by Cgx on 4/2/2023 in #djs-questions
Bot crashes after running a servercreate command
Hey, I have some problems with one of my commands,. So it should simply create a discord server from a server template , but it's crashing with an error code, i'll provide you. It would be really nice if someone can help.
Code:
Error:
Node.js: v18.15.0
Discord.js: See Tag
const { Client, GatewayIntentBits } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { token, clientId, guildId } = require('./config.json');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity('CHAD IS FAT');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply(`Pong! ${Math.round(client.ws.ping)}ms.`);
} else if (interaction.commandName === 'serversetup') {
const option = interaction.options.getString('template');
let templateLink = '';
if (option === 'Community') {
templateLink = 'https://discord.new/VBRryPvhAk5N';
} else if (option === 'Advertising') {
templateLink = 'https://discord.new/cwczv577CtDe';
}
await interaction.reply(`Loading ${option} template...`);
const guild = await interaction.guild.templates.create({ sourceGuildId: null, name: null, code: templateLink });
await interaction.followUp(`Template loaded successfully! Here is the invite link to the new server: https://discord.gg/${guild.code}`);
}
});
const pingCommand = new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with the current Ping!');
const serversetupCommand = new SlashCommandBuilder()
.setName('serversetup')
.setDescription('Setups the Server for you.')
.addStringOption(option =>
option.setName('template')
.setDescription('Choose your Server Topic.')
.setRequired(true)
.addChoices(
{ name: 'Community', value: 'Community' },
{ name: 'Advertising', value: 'Advertising' },
));
const commands = [
pingCommand.toJSON(),
serversetupCommand.toJSON()
];
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
try {
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Successfully registered application commands.');
} catch (error) {
console.error(error);
}
})();
client.login(token);
const { Client, GatewayIntentBits } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { token, clientId, guildId } = require('./config.json');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity('CHAD IS FAT');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply(`Pong! ${Math.round(client.ws.ping)}ms.`);
} else if (interaction.commandName === 'serversetup') {
const option = interaction.options.getString('template');
let templateLink = '';
if (option === 'Community') {
templateLink = 'https://discord.new/VBRryPvhAk5N';
} else if (option === 'Advertising') {
templateLink = 'https://discord.new/cwczv577CtDe';
}
await interaction.reply(`Loading ${option} template...`);
const guild = await interaction.guild.templates.create({ sourceGuildId: null, name: null, code: templateLink });
await interaction.followUp(`Template loaded successfully! Here is the invite link to the new server: https://discord.gg/${guild.code}`);
}
});
const pingCommand = new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with the current Ping!');
const serversetupCommand = new SlashCommandBuilder()
.setName('serversetup')
.setDescription('Setups the Server for you.')
.addStringOption(option =>
option.setName('template')
.setDescription('Choose your Server Topic.')
.setRequired(true)
.addChoices(
{ name: 'Community', value: 'Community' },
{ name: 'Advertising', value: 'Advertising' },
));
const commands = [
pingCommand.toJSON(),
serversetupCommand.toJSON()
];
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
try {
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Successfully registered application commands.');
} catch (error) {
console.error(error);
}
})();
client.login(token);
throw er; // Unhandled 'error' event
^
TypeError: Cannot read properties of undefined (reading 'create')
at Client.<anonymous> (C:\Users\user\ServerMaster\bot.js:37:53)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
throw er; // Unhandled 'error' event
^
TypeError: Cannot read properties of undefined (reading 'create')
at Client.<anonymous> (C:\Users\user\ServerMaster\bot.js:37:53)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
51 replies
DIAdiscord.js - Imagine a bot
•Created by Cgx on 4/1/2023 in #djs-questions
TypeError: Cannot read properties of undefined (reading 'FLAGS')
Hello, I got an error with the flags. Could someone help?
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_CHANNELS] });
client.login('token replaced');
async function createChannelsCommand(interaction) {
await interaction.deferReply();
const category = await interaction.guild.channels.create('important', {
type: 'category'
});
await interaction.guild.channels.create('rules', {
type: 'text',
parent: category.id
});
await interaction.guild.channels.create('announcements', {
type: 'text',
parent: category.id
});
await interaction.guild.channels.create('welcome', {
type: 'text',
parent: category.id
});
await interaction.editReply('Done!');
}
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_CHANNELS] });
client.login('token replaced');
async function createChannelsCommand(interaction) {
await interaction.deferReply();
const category = await interaction.guild.channels.create('important', {
type: 'category'
});
await interaction.guild.channels.create('rules', {
type: 'text',
parent: category.id
});
await interaction.guild.channels.create('announcements', {
type: 'text',
parent: category.id
});
await interaction.guild.channels.create('welcome', {
type: 'text',
parent: category.id
});
await interaction.editReply('Done!');
}
53 replies