tenfy
tenfy
DIAdiscord.js - Imagine an app
Created by tenfy on 6/6/2024 in #djs-questions
Can't set role icon
Discord.js version: 14.15.3 Node version: v20.5.1
Code:
const customEmojis = content.match(/<a?:\w+:(\d+)>/g);
const attachments = message.attachments;

let response;
if (customEmojis) {
response = await axios.get(`https://cdn.discordapp.com/emojis/${customEmojis[0].match(/:(\d+)>/)[1]}.png`, { responseType: "arraybuffer" })
} else if (attachments) {
response = await axios.get(attachments.first().url, { responseType: "arraybuffer" });
}
console.log(response.data);
await discordRole.setIcon(response.data);
const customEmojis = content.match(/<a?:\w+:(\d+)>/g);
const attachments = message.attachments;

let response;
if (customEmojis) {
response = await axios.get(`https://cdn.discordapp.com/emojis/${customEmojis[0].match(/:(\d+)>/)[1]}.png`, { responseType: "arraybuffer" })
} else if (attachments) {
response = await axios.get(attachments.first().url, { responseType: "arraybuffer" });
}
console.log(response.data);
await discordRole.setIcon(response.data);
I get no errors, so i have no idea what to do. The bot has Administrator permissions.
3 replies
DIAdiscord.js - Imagine an app
Created by tenfy on 4/19/2023 in #djs-questions
DiscordAPIError[0]: 405: Method Not Allowed
Hello, i have this code:
const { CommandInteraction, ChannelType, ButtonInteraction, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits, ModalBuilder, TextInputBuilder, TextInputStyle, ThreadMemberFlags } = require("discord.js");

module.exports = {
name: "threadMembersUpdate",

async execute(newMembers, oldMembers, thread) {

const threadName = `${thread.name}`

if (!threadName.includes("menu")) return

const threadMember = newMembers.firstKey()

try {
await thread.members.remove(threadMember);
} catch (err) {
console.log(err)
}

},
};
const { CommandInteraction, ChannelType, ButtonInteraction, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits, ModalBuilder, TextInputBuilder, TextInputStyle, ThreadMemberFlags } = require("discord.js");

module.exports = {
name: "threadMembersUpdate",

async execute(newMembers, oldMembers, thread) {

const threadName = `${thread.name}`

if (!threadName.includes("menu")) return

const threadMember = newMembers.firstKey()

try {
await thread.members.remove(threadMember);
} catch (err) {
console.log(err)
}

},
};
it works fine and removes users from thread, but every time i get error message:
DiscordAPIError[0]: 405: Method Not Allowed
at SequentialHandler.runRequest (D:\job\discord\Lumen\node_modules\@discordjs\rest\dist\index.js:933:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (D:\job\discord\Lumen\node_modules\@discordjs\rest\dist\index.js:712:14)
at async REST.request (D:\job\discord\Lumen\node_modules\@discordjs\rest\dist\index.js:1321:22)
at async ThreadMemberManager.remove (D:\job\discord\Lumen\node_modules\discord.js\src\managers\ThreadMemberManager.js:111:5)
at async Object.execute (D:\job\discord\Lumen\Events\Tickets\ThreadRemove.js:14:9)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
rawError: { message: '405: Method Not Allowed', code: 0 },
code: 0,
status: 405,
method: 'DELETE',
url: 'https://discord.com/api/v10/channels/1098282953747996723/thread-members',
requestBody: { files: undefined, json: undefined }
}
DiscordAPIError[0]: 405: Method Not Allowed
at SequentialHandler.runRequest (D:\job\discord\Lumen\node_modules\@discordjs\rest\dist\index.js:933:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (D:\job\discord\Lumen\node_modules\@discordjs\rest\dist\index.js:712:14)
at async REST.request (D:\job\discord\Lumen\node_modules\@discordjs\rest\dist\index.js:1321:22)
at async ThreadMemberManager.remove (D:\job\discord\Lumen\node_modules\discord.js\src\managers\ThreadMemberManager.js:111:5)
at async Object.execute (D:\job\discord\Lumen\Events\Tickets\ThreadRemove.js:14:9)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
rawError: { message: '405: Method Not Allowed', code: 0 },
code: 0,
status: 405,
method: 'DELETE',
url: 'https://discord.com/api/v10/channels/1098282953747996723/thread-members',
requestBody: { files: undefined, json: undefined }
}
Ty for help catKiss
7 replies
DIAdiscord.js - Imagine an app
Created by tenfy on 3/27/2023 in #djs-questions
Select menu
When I select an option in the select menu, it changes the message as I need, but then clicks the button itself. https://sourceb.in/VaOKb5cNrh https://sourceb.in/cSdgoTX6Uj
6 replies
DIAdiscord.js - Imagine an app
Created by tenfy on 3/19/2023 in #djs-questions
Guilds count in shards
How can I get the number of guilds in a shard in my index js file?
const { ShardingManager } = require("discord.js");
const config = require("./config.json");
const ascii = require("ascii-table");

const table = new ascii().setHeading("Shards", "Guilds");

const manager = new ShardingManager("./salvation.js", { token: config.token });

manager.on("shardCreate", shard => {
const shardCount = manager.totalShards;
const shardName = `Shard ${shard.id}`;
const shardGuildsCount = "something"
table.addRow(shardName);
console.log(table.toString());
});

manager.spawn();
const { ShardingManager } = require("discord.js");
const config = require("./config.json");
const ascii = require("ascii-table");

const table = new ascii().setHeading("Shards", "Guilds");

const manager = new ShardingManager("./salvation.js", { token: config.token });

manager.on("shardCreate", shard => {
const shardCount = manager.totalShards;
const shardName = `Shard ${shard.id}`;
const shardGuildsCount = "something"
table.addRow(shardName);
console.log(table.toString());
});

manager.spawn();
4 replies
DIAdiscord.js - Imagine an app
Created by tenfy on 3/15/2023 in #djs-questions
voice system
I have this code:
const { ChannelType, ButtonInteraction, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits, ModalBuilder, TextInputBuilder, TextInputStyle, CommandInteraction, Client, joinVoiceChannel } = require("discord.js");
const UserVoice = require("../../Models/UserVoice");
const VoiceSchema = require("../../Models/VoiceSchema");

async function checkEmptyVoiceChannel(voice_channel) {
if (voice_channel && voice_channel.members.size === 0) {
await voice_channel.delete();
console.log(`Deleted voice channel ${voice_channel.name} (${voice_channel.id}) because it was empty`);
}
}

module.exports = {
name: "voiceStateUpdate",

async execute(oldVoiceState, newVoiceState) {
const VoiceData = await VoiceSchema.findOne({ GuildID: newVoiceState.guild.id });
const UserData = await UserVoice.findOne({ UserID: newVoiceState.member.id });
let voice_channel;

if (newVoiceState.channel && newVoiceState.channel.id === VoiceData.ChannelID) {
voice_channel = await newVoiceState.guild.channels.create({
name: `${newVoiceState.member.displayName}-voice`,
type: ChannelType.GuildVoice,
parent: newVoiceState.channel.parent
})
await UserVoice.findOneAndUpdate(
{ UserID: newVoiceState.member.id },
{
ChannelID: voice_channel.id,
},
{
new: true,
upsert: true,
}
)

await newVoiceState.member.voice.setChannel(voice_channel);

} else if (oldVoiceState.channel.id === voice_channel.id && oldVoiceState.channel.members.size === 0) {
await checkEmptyVoiceChannel(oldVoiceState.channel);
}

},
};
const { ChannelType, ButtonInteraction, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits, ModalBuilder, TextInputBuilder, TextInputStyle, CommandInteraction, Client, joinVoiceChannel } = require("discord.js");
const UserVoice = require("../../Models/UserVoice");
const VoiceSchema = require("../../Models/VoiceSchema");

async function checkEmptyVoiceChannel(voice_channel) {
if (voice_channel && voice_channel.members.size === 0) {
await voice_channel.delete();
console.log(`Deleted voice channel ${voice_channel.name} (${voice_channel.id}) because it was empty`);
}
}

module.exports = {
name: "voiceStateUpdate",

async execute(oldVoiceState, newVoiceState) {
const VoiceData = await VoiceSchema.findOne({ GuildID: newVoiceState.guild.id });
const UserData = await UserVoice.findOne({ UserID: newVoiceState.member.id });
let voice_channel;

if (newVoiceState.channel && newVoiceState.channel.id === VoiceData.ChannelID) {
voice_channel = await newVoiceState.guild.channels.create({
name: `${newVoiceState.member.displayName}-voice`,
type: ChannelType.GuildVoice,
parent: newVoiceState.channel.parent
})
await UserVoice.findOneAndUpdate(
{ UserID: newVoiceState.member.id },
{
ChannelID: voice_channel.id,
},
{
new: true,
upsert: true,
}
)

await newVoiceState.member.voice.setChannel(voice_channel);

} else if (oldVoiceState.channel.id === voice_channel.id && oldVoiceState.channel.members.size === 0) {
await checkEmptyVoiceChannel(oldVoiceState.channel);
}

},
};
But when i leave my channel i get an error: TypeError: Cannot read properties of undefined (reading 'id') at Object.execute (D:\job\Discord\Salvation\Events\Voice\voiceStateUpdate.js:39:63) 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)
8 replies
DIAdiscord.js - Imagine an app
Created by tenfy on 2/25/2023 in #djs-questions
TypeError: conn.send is not a function
I have 2 files and i need to import variable from one to another, but it doesn't work https://sourceb.in/q25DwZCRmI https://sourceb.in/LevK9HoTqj
3 replies
DIAdiscord.js - Imagine an app
Created by tenfy on 2/15/2023 in #djs-questions
TypeError: Cannot read properties of undefined (reading 'getTextInputValue')
https://sourceb.in/GVG52tboOv this is my JavaScript file. I want when I send modal it will send value of textinput into console just for test, but I`m having an error: TypeError: Cannot read properties of undefined (reading 'getTextInputValue')
15 replies