Hi my problem is if any user trigger a command or a button (a interaction), then it triggers this line: "await member.send('Du bist bereits auf YANKEEUNIT91 COMMUNITY verifiziert!');" in Code 1.
Example: A user trigger the button in Code 2, he get the DM message from the bot from code 1.
What makes code 1?
It's a verification system, you press the button choose in a select menu that you accept the rules then it open a Modal where you enter you server nickname, then you select in a other select menu a ping role.
You get the nickname the choosed role and the member role from the bot.
But if you already a member this line in code 1 triggers and send you the DM "if (interaction.member.roles.cache.has('707275842295955530')) {".
But for some reason the bot sends the DM even when other interactions are triggered.
Code 1:
const Discord = require('discord.js')
const Command = require('../../structures/CommandClass');
const { stripIndents } = require('common-tags');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, TextInputStyle, StringSelectMenuBuilder, Events, ModalBuilder, TextInputBuilder } = require('discord.js');
let ninputvalues = {};
module.exports = class verifiy extends Command {
constructor(client) {
super(client, {
data: new SlashCommandBuilder()
.setName('sendverifizierung')
.setDescription('Sende das Verifizierungs Embed')
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),
});
}
async run(client, interaction) {
let member = await interaction.member.fetch();
const verifiychannelID = '1052951990331773019';
const verifiychannel = member.guild.channels.cache.get(verifiychannelID);
const glocke = interaction.guild.roles.cache.get('884820297977573386');
const news = interaction.guild.roles.cache.get('1032524990274351134');
const memberrole = interaction.guild.roles.cache.get('707275842295955530');
let failsafe = false;
const rulesmenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('rulesmenü')
.setPlaceholder('Antwort auswählen')
.addOptions(
{
label: 'Ja, gelesen und einverstanden.',
value: 'ja',
},
{
label: 'Nein, nicht gelsesen und nicht einverstanden.',
value: 'nein',
},
),
);
const rolemenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('rolemenü')
.setPlaceholder('Rolle auswählen')
.addOptions(
{
label: 'YU91 Glocke',
description: 'Erhalte extra Benachrichtigungen über Yankeeunit91.',
value: 'glocke',
},
{
label: 'Gaming News',
description: 'Erhalte extra Benachrichtigungen für Neue Infos über z.B Spiele etc.',
value: 'news',
},
{
label: 'Keine',
description: 'Erhalte keine Rolle.',
value: 'keine',
},
),
);
const modalsv = new ModalBuilder()
.setCustomId('ninput')
.setTitle('YANKEEUNIT91 COMMUNITY');
const nameinput = new TextInputBuilder()
.setCustomId('nameinput')
.setLabel("Server Nickname")
.setPlaceholder('Keine Sonderzeichen!')
.setStyle(TextInputStyle.Short)
.setMinLength(2)
.setMaxLength(32)
.setRequired(true);
const firstActionRowv = new ActionRowBuilder().addComponents(nameinput);
modalsv.addComponents(firstActionRowv);
const verifeembed = new EmbedBuilder()
.setTitle(`Verifizieren dich!`)
.setColor('#00ff0c')
.setDescription(stripIndents`Durch das verifizieren erhälst du zugriff auf die YANKEEUNIT91 COMMUNITY!`)
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp();
const buttonva = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('buttonanfrageverify')
.setEmoji('✅')
.setLabel('Verifizieren')
.setStyle(ButtonStyle.Success),
);
client.on('interactionCreate', async interaction => {
const member = await interaction.member.fetch();
if (interaction.member.roles.cache.has('707275842295955530')) {
await member.send('**Du bist bereits auf YANKEEUNIT91 COMMUNITY verifiziert!**');
return interaction.deferUpdate()
} else if (interaction.isButton()) {
const buttonID = interaction.customId
if (buttonID === 'buttonanfrageverify') {
await interaction.reply({ content:'**Hast du die Regeln gelesen, und bist du damit einverstanden?**', components: [rulesmenü], ephemeral: true });
}
}
});
client.on('interactionCreate', async interaction => {
if (interaction.isStringSelectMenu()) {
const selected = interaction.values.join(', ');
if (selected === 'ja') {
await interaction.showModal(modalsv);
} else if (selected === 'nein') {
await interaction.update({ content:'**Lese dir die Regeln erneut durch! Solltest du nicht mit denn Regeln einverstanden sein, bitten wir dich denn Server zu verlassen.**', components: [], ephemeral: true });
}
}
});
verifiychannel.send({ embeds: [verifeembed], components: [buttonva] });
await interaction.reply({ content: 'Verifizierungs Embed wurde versendet!', ephemeral: true });
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isModalSubmit()) {
if (interaction.customId === "ninput") {
await interaction.update({ content:'**Wähle eine Role für die du dich interresierst!**', components: [rolemenü], ephemeral: true });
var ninputdata = interaction.fields.getTextInputValue('nameinput');
ninputvalues[interaction.user.id] = interaction.fields.getTextInputValue('nameinput');
ninputvalues[interaction.user.id] = ninputvalues[interaction.user.id].replace(/[^a-zA-Z0-9 ]/g, 'X');
}
} else if (interaction.isStringSelectMenu()) {
const selected = interaction.values[0];
const member = await interaction.member.fetch();
if (selected === 'glocke') {
await interaction.update({ content:'**Du hast die \`YU91 Glocke\` erhalten. Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await member.roles.add(glocke)
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
return await member.roles.add(memberrole);
} else if (selected === 'news') {
await interaction.update({ content:'**Du hast die \`Gaming News\` erhalten. Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await member.roles.add(news)
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
return await member.roles.add(memberrole);
} else if (selected === 'keine') {
await interaction.update({ content:'**Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
await member.roles.add(memberrole);
}
};
});
}
};
Code 2
const Discord = require('discord.js')
const Command = require('../../structures/CommandClass');
const { stripIndents } = require('common-tags');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, TextInputStyle, StringSelectMenuBuilder, Events, ModalBuilder, TextInputBuilder } = require('discord.js');
let sinputvalues = {};
let ginputvalues = {};
let pfmenüvalues = {};
module.exports = class spielersuche extends Command {
constructor(client) {
super(client, {
data: new SlashCommandBuilder()
.setName('sendspielersuche')
.setDescription('Sende das Spielersuche Embed')
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),
});
}
async run(client, interaction) {
let member = await interaction.member.fetch();
const anfragechannelID = '889302458906591344';
const anfragechannel = member.guild.channels.cache.get(anfragechannelID);
const createanfragechannelID = '1052951990331773019';
const createanfragechannel = member.guild.channels.cache.get(createanfragechannelID);
const pfmenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('pfmenü')
.setPlaceholder('Plattform auswählen (Scrollen)')
.addOptions(
{
label: 'PS4',
value: 'PS4',
},
{
label: 'PS5',
value: 'PS5',
},
{
label: 'PS4/PS5',
value: 'PS4/PS5',
},
{
label: 'PC',
value: 'PC',
},
{
label: 'Switch',
value: 'Switch',
},
{
label: 'Xbox One',
value: 'Xbox One',
},
{
label: 'Xbox Series',
value: 'Xbox Series',
},
{
label: 'Xbox One/Xbox Series',
value: 'Xbox One/Xbox Series',
},
{
label: 'Alle',
value: 'Alle',
},
),
);
const spmenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('spmenü')
.setPlaceholder('Mitspieleranzahl auswählen (Scrollen)')
.addOptions(
{
label: '1',
value: '1 Mitspieler',
},
{
label: '2',
value: '2 Mitspieler',
},
{
label: '3',
value: '3 Mitspieler',
},
{
label: '4',
value: '4 Mitspieler',
},
{
label: '5',
value: '5 Mitspieler',
},
{
label: '6',
value: '6 Mitspieler',
},
{
label: '7',
value: '7 Mitspieler',
},
{
label: '8',
value: '8 Mitspieler',
},
{
label: '9+',
value: '9+ Mitspieler',
},
),
);
const modals = new ModalBuilder()
.setCustomId('minput')
.setTitle('Spielersuche 🔎');
const spielinput = new TextInputBuilder()
.setCustomId('spielinput')
.setLabel("Für welches Spiel?")
.setPlaceholder('GTA5, Fortnite, Call of Duty, Minecraft ...')
.setStyle(TextInputStyle.Short)
.setMinLength(2)
.setMaxLength(20)
.setRequired(true);
const grundinput = new TextInputBuilder()
.setCustomId('grundinput')
.setLabel("Der Grund der Anfrage?")
.setPlaceholder('Beispiel: Suche Spieler für Cayo Perico Heist.')
.setStyle(TextInputStyle.Short)
.setMinLength(10)
.setMaxLength(60)
.setRequired(true);
const firstActionRow = new ActionRowBuilder().addComponents(spielinput);
const secondActionRow = new ActionRowBuilder().addComponents(grundinput);
modals.addComponents(firstActionRow, secondActionRow);
const spielersucheerweitertEmbed = new EmbedBuilder()
.setTitle(`Spieler suchen Spieler 🔎`)
.setColor('#00ff0c')
.setDescription(stripIndents`Drücke auf denn Button um eine Spielersuche Anzufragen!`)
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp();
const buttonsa = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('buttonanfrage')
.setEmoji('🔎')
.setLabel('Spielersuche Anfragen')
.setStyle(ButtonStyle.Success),
);
client.on('interactionCreate', async interaction => {
if (interaction.isButton()) {
const buttonID = interaction.customId
if (buttonID === 'buttonanfrage') {
await interaction.showModal(modals);
}
}
});
createanfragechannel.send({ embeds: [spielersucheerweitertEmbed], components: [buttonsa] });
await interaction.reply({ content: 'Spielersuche Embed wurde versendet!', ephemeral: true });
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isModalSubmit()) {
if (interaction.customId === "minput") {
await interaction.reply({ content:'**Wähle deine Plattform!**', components: [pfmenü], ephemeral: true });
var ginputdata = interaction.fields.getTextInputValue('grundinput');
ginputvalues[interaction.user.id] = interaction.fields.getTextInputValue('grundinput');
var sinputdata = interaction.fields.getTextInputValue('spielinput');
sinputvalues[interaction.user.id] = interaction.fields.getTextInputValue('spielinput');
}
} else if (interaction.isStringSelectMenu()) {
if (interaction.customId === "pfmenü") {
await interaction.update({ content:'**Wähle wie viele Mitpsieler gesucht werden!**', components: [spmenü], ephemeral: true });
var pfmenüdata = interaction.values.join(', ');
pfmenüvalues[interaction.user.id] = interaction.values.join(', ');
}
const spanzahl = await interaction.values.join(', ');
const spielersucheerweitertEmbedfertig = new EmbedBuilder()
.setTitle(`${ginputvalues[interaction.user.id]}`)
.setColor('#00ff0c')
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp()
.addFields(
{
name: '**Spiel:**',
value: `${sinputvalues[interaction.user.id]}`,
inline: true,
},
{
name: `**Plattform:**`,
value: `${pfmenüvalues[interaction.user.id]}`,
inline: false,
},
{
name: `**Mitspieleranzahl gesucht:**`,
value: `${spanzahl}`,
inline: false,
},
);
if (interaction.customId === "spmenü") {
const member = await interaction.member.fetch();
await interaction.update({ content:'**Spielersuche erfolgreich Angefragt!**', components: [], ephemeral: true });
return await anfragechannel.send({ content: `**Anfrage von:** <#${member.id}>`, embeds: [spielersucheerweitertEmbedfertig] });
}
};
});
}
};
I didnt know why it is but i think form this line: "const member = await interaction.member.fetch();" in code 1, but i dont know how to fix that.
Hi Thanks #Tetie i Fixed it. I write all interactionCreate Events to one interactionCreate Event, replaced the const member = await interaction.member.fetch(); with interaction.member.
And i changed some on the syntax.
Code Befor:
const Command = require('../../structures/CommandClass');
const { stripIndents } = require('common-tags');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, TextInputStyle, StringSelectMenuBuilder, Events, ModalBuilder, TextInputBuilder } = require('discord.js');
let ninputvalues = {};
module.exports = class verifiy extends Command {
constructor(client) {
super(client, {
data: new SlashCommandBuilder()
.setName('sendverifizierung')
.setDescription('Sende das Verifizierungs Embed')
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),
});
}
async run(client, interaction) {
let member = await interaction.member.fetch();
const verifiychannelID = '1052951990331773019';
const verifiychannel = member.guild.channels.cache.get(verifiychannelID);
const glocke = interaction.guild.roles.cache.get('884820297977573386');
const news = interaction.guild.roles.cache.get('1032524990274351134');
const memberrole = interaction.guild.roles.cache.get('707275842295955530');
let failsafe = false;
const rulesmenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('rulesmenü')
.setPlaceholder('Antwort auswählen')
.addOptions(
{
label: 'Ja, gelesen und einverstanden.',
value: 'ja',
},
{
label: 'Nein, nicht gelsesen und nicht einverstanden.',
value: 'nein',
},
),
);
const rolemenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('rolemenü')
.setPlaceholder('Rolle auswählen')
.addOptions(
{
label: 'YU91 Glocke',
description: 'Erhalte extra Benachrichtigungen über Yankeeunit91.',
value: 'glocke',
},
{
label: 'Gaming News',
description: 'Erhalte extra Benachrichtigungen für Neue Infos über z.B Spiele etc.',
value: 'news',
},
{
label: 'Keine',
description: 'Erhalte keine Rolle.',
value: 'keine',
},
),
);
const modalsv = new ModalBuilder()
.setCustomId('ninput')
.setTitle('YANKEEUNIT91 COMMUNITY');
const nameinput = new TextInputBuilder()
.setCustomId('nameinput')
.setLabel("Server Nickname")
.setPlaceholder('Keine Sonderzeichen!')
.setStyle(TextInputStyle.Short)
.setMinLength(2)
.setMaxLength(32)
.setRequired(true);
const firstActionRowv = new ActionRowBuilder().addComponents(nameinput);
modalsv.addComponents(firstActionRowv);
const verifeembed = new EmbedBuilder()
.setTitle(`Verifizieren dich!`)
.setColor('#00ff0c')
.setDescription(stripIndents`Durch das verifizieren erhälst du zugriff auf die YANKEEUNIT91 COMMUNITY!`)
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp();
const buttonva = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('buttonanfrageverify')
.setEmoji('✅')
.setLabel('Verifizieren')
.setStyle(ButtonStyle.Success),
);
client.on('interactionCreate', async interaction => {
const member = await interaction.member.fetch();
if (interaction.member.roles.cache.has('707275842295955530')) {
await member.send('**Du bist bereits auf YANKEEUNIT91 COMMUNITY verifiziert!**');
return interaction.deferUpdate()
} else if (interaction.isButton()) {
const buttonID = interaction.customId
if (buttonID === 'buttonanfrageverify') {
await interaction.reply({ content:'**Hast du die Regeln gelesen, und bist du damit einverstanden?**', components: [rulesmenü], ephemeral: true });
}
}
});
client.on('interactionCreate', async interaction => {
if (interaction.isStringSelectMenu()) {
const selected = interaction.values.join(', ');
if (selected === 'ja') {
await interaction.showModal(modalsv);
} else if (selected === 'nein') {
await interaction.update({ content:'**Lese dir die Regeln erneut durch! Solltest du nicht mit denn Regeln einverstanden sein, bitten wir dich denn Server zu verlassen.**', components: [], ephemeral: true });
}
}
});
verifiychannel.send({ embeds: [verifeembed], components: [buttonva] });
await interaction.reply({ content: 'Verifizierungs Embed wurde versendet!', ephemeral: true });
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isModalSubmit()) {
if (interaction.customId === "ninput") {
await interaction.update({ content:'**Wähle eine Role für die du dich interresierst!**', components: [rolemenü], ephemeral: true });
var ninputdata = interaction.fields.getTextInputValue('nameinput');
ninputvalues[interaction.user.id] = interaction.fields.getTextInputValue('nameinput');
ninputvalues[interaction.user.id] = ninputvalues[interaction.user.id].replace(/[^a-zA-Z0-9 ]/g, 'X');
}
} else if (interaction.isStringSelectMenu()) {
const selected = interaction.values[0];
const member = await interaction.member.fetch();
if (selected === 'glocke') {
await interaction.update({ content:'**Du hast die \`YU91 Glocke\` erhalten. Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await member.roles.add(glocke)
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
return await member.roles.add(memberrole);
} else if (selected === 'news') {
await interaction.update({ content:'**Du hast die \`Gaming News\` erhalten. Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await member.roles.add(news)
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
return await member.roles.add(memberrole);
} else if (selected === 'keine') {
await interaction.update({ content:'**Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
await member.roles.add(memberrole);
}
};
});
}
};
After:
const Discord = require('discord.js')
const Command = require('../../structures/CommandClass');
const { stripIndents } = require('common-tags');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, TextInputStyle, StringSelectMenuBuilder, Events, ModalBuilder, TextInputBuilder } = require('discord.js');
let ninputvalues = {};
module.exports = class verifiy extends Command {
constructor(client) {
super(client, {
data: new SlashCommandBuilder()
.setName('sendverifizierung')
.setDescription('Sende das Verifizierungs Embed')
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),
});
}
async run(client, interaction) {
const verifiychannelID = '644218169422250014';
const verifiychannel = interaction.guild.channels.cache.get(verifiychannelID);
const glocke = interaction.guild.roles.cache.get('884820297977573386');
const news = interaction.guild.roles.cache.get('1032524990274351134');
const memberrole = interaction.guild.roles.cache.get('707275842295955530');
let failsafe = false;
const rulesmenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('rulesmenü')
.setPlaceholder('Antwort auswählen')
.addOptions(
{
label: 'Ja, gelesen und einverstanden.',
value: 'ja',
},
{
label: 'Nein, nicht gelsesen und nicht einverstanden.',
value: 'nein',
},
),
);
const rolemenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('rolemenü')
.setPlaceholder('Rolle auswählen')
.addOptions(
{
label: 'YU91 Glocke',
description: 'Erhalte extra Benachrichtigungen über Yankeeunit91.',
value: 'glocke',
},
{
label: 'Gaming News',
description: 'Erhalte extra Benachrichtigungen für Neue Infos über z.B Spiele etc.',
value: 'news',
},
{
label: 'Keine',
description: 'Erhalte keine Rolle.',
value: 'keine',
},
),
);
const modalsv = new ModalBuilder()
.setCustomId('ninput')
.setTitle('YANKEEUNIT91 COMMUNITY');
const nameinput = new TextInputBuilder()
.setCustomId('nameinput')
.setLabel("Server Nickname")
.setPlaceholder('Keine Sonderzeichen!')
.setStyle(TextInputStyle.Short)
.setMinLength(2)
.setMaxLength(32)
.setRequired(true);
const firstActionRowv = new ActionRowBuilder().addComponents(nameinput);
modalsv.addComponents(firstActionRowv);
const verifeembed = new EmbedBuilder()
.setTitle(`Verifizieren dich!`)
.setColor('#00ff0c')
.setDescription(stripIndents`Durch das verifizieren erhälst du zugriff auf die YANKEEUNIT91 COMMUNITY!`)
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp();
const buttonva = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('buttonanfrageverify')
.setEmoji('✅')
.setLabel('Verifizieren')
.setStyle(ButtonStyle.Success),
);
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isButton()) {
const buttonID = interaction.customId
if (buttonID === 'buttonanfrageverify') {
if (interaction.member.roles.cache.has('707275842295955530')) {
await interaction.reply({ content: '**Du bist bereits auf YANKEEUNIT91 COMMUNITY verifiziert!**', ephemeral: true });
}
else await interaction.reply({ content:'**Hast du die Regeln gelesen, und bist du damit einverstanden?**', components: [rulesmenü], ephemeral: true });
}
} else if (interaction.isStringSelectMenu()) {
const selected = interaction.values.join(', ');
if (selected === 'ja') {
await interaction.showModal(modalsv);
} else if (selected === 'nein') {
await interaction.update({ content:'**Lese dir die Regeln erneut durch! Solltest du nicht mit denn Regeln einverstanden sein, bitten wir dich denn Server zu verlassen.**', components: [], ephemeral: true });
}
} if (interaction.isModalSubmit()) {
if (interaction.customId === "ninput") {
await interaction.update({ content:'**Wähle eine Role für die du dich interresierst!**', components: [rolemenü], ephemeral: true });
var ninputdata = interaction.fields.getTextInputValue('nameinput');
ninputvalues[interaction.user.id] = interaction.fields.getTextInputValue('nameinput');
ninputvalues[interaction.user.id] = ninputvalues[interaction.user.id].replace(/[^a-zA-Z0-9 ]/g, 'X');
}
} else if (interaction.isStringSelectMenu()) {
const selected = interaction.values[0];
if (selected === 'glocke') {
await interaction.update({ content:'**Du hast die \`YU91 Glocke\` erhalten. Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await interaction.member.roles.add(glocke)
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
return await interaction.member.roles.add(memberrole);
} else if (selected === 'news') {
await interaction.update({ content:'**Du hast die \`Gaming News\` erhalten. Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await interaction.member.roles.add(news)
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
return await interaction.member.roles.add(memberrole);
} else if (selected === 'keine') {
await interaction.update({ content:'**Willkommen in der YANKEEUNIT91 COMMUNITY!**', components: [], ephemeral: true });
await interaction.member.setNickname(`${ninputvalues[interaction.user.id]}`).catch(e => (failsafe = true));
await interaction.member.roles.add(memberrole);
}
};
});
verifiychannel.send({ embeds: [verifeembed], components: [buttonva] });
await interaction.reply({ content: 'Verifizierungs Embed wurde versendet!', ephemeral: true });
}
};```
Respons Picture
Hi my Bot always replies one more message, The command works you press the button enter a reason in the text input field and then you select a platform from the drop down menu. But instead of sending the embed once, it sends it multiple times each time.
Error: Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
Or: "Interaction has already been acknowledged."
const Discord = require('discord.js')
const Command = require('../../structures/CommandClass');
const { stripIndents } = require('common-tags');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, TextInputStyle, StringSelectMenuBuilder, Events, ModalBuilder, TextInputBuilder } = require('discord.js');
module.exports = class spielersucheerweitert extends Command {
constructor(client) {
super(client, {
data: new SlashCommandBuilder()
.setName('sendspielersuche')
.setDescription('Sende das Spielersuche Embed')
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),
});
}
async run(client, interaction) {
let member = await interaction.member.fetch();
const pfmenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('pfmenü')
.setPlaceholder('Plattform auswählen')
.addOptions(
{
label: 'PS4',
value: 'ps4',
},
{
label: 'PS5',
value: 'ps5',
},
{
label: 'PS4/PS5',
value: 'ps4ps5',
},
{
label: 'PC',
value: 'pc',
},
{
label: 'Switch',
value: 'switch',
},
{
label: 'Alle',
value: 'alle',
},
),
);
const modals = new ModalBuilder()
.setCustomId('minput')
.setTitle('Spielersuche 🔎');
const spielinput = new TextInputBuilder()
.setCustomId('spielinput')
.setLabel("Für welches Spiel?")
.setPlaceholder('GTA5, Fortnite, Call of Duty, Minecraft ...')
.setStyle(TextInputStyle.Short)
.setMinLength(2)
.setMaxLength(20)
.setRequired(true);
const grundinput = new TextInputBuilder()
.setCustomId('grundinput')
.setLabel("Der Grund der Anfrage?")
.setPlaceholder('Beispiel: Suche Spieler für Cayo Perico Heist.')
.setStyle(TextInputStyle.Short)
.setMinLength(10)
.setMaxLength(60)
.setRequired(true);
const firstActionRow = new ActionRowBuilder().addComponents(spielinput);
const secondActionRow = new ActionRowBuilder().addComponents(grundinput);
modals.addComponents(firstActionRow, secondActionRow);
const spielersucheerweitertEmbed = new EmbedBuilder()
.setTitle(`Spieler suchen Spieler 🔎`)
.setColor('#00ff0c')
.setDescription(stripIndents`Drücke auf denn Button um eine Spielersuche Anzufragen!`)
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp();
const buttonsa = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('buttonanfrage')
.setEmoji('🔎')
.setLabel('Spielersuche Anfragen')
.setStyle(ButtonStyle.Success),
);
client.on('interactionCreate', async interaction => {
if (interaction.isButton()) {
const buttonID = interaction.customId
if (buttonID === 'buttonanfrage') {
await interaction.showModal(modals);
}
}
});
client.on('interactionCreate', (modalSubmit) => {
if (!modalSubmit.isModalSubmit()) return;
const ginputdata = modalSubmit.fields.getTextInputValue('grundinput');
const sinputdata = modalSubmit.fields.getTextInputValue('spielinput');
modalSubmit.reply({
content:'**Wähle deine Plattform!**', components: [pfmenü], ephemeral: true });
client.on('interactionCreate', async interaction => {
if (!interaction.isStringSelectMenu()) return;
const selected = await interaction.values.join(', ');
const spielersucheerweitertEmbedfertig = new EmbedBuilder()
.setTitle(`${ginputdata}`)
.setColor('#00ff0c')
.setDescription(stripIndents`Spiel: \`${sinputdata}\`
Plattform: \`${selected}\``)
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp();
await interaction.channel.send({ embeds: [spielersucheerweitertEmbedfertig] });
return await interaction.update({ content: '**Spielersuche wurde erfolgreich Angefragt!**', components: [] });
});
});
await interaction.channel.send({ embeds: [spielersucheerweitertEmbed], components: [buttonsa] });
return await interaction.reply({ content: 'Spielersuche Embed wurde versendet!', ephemeral: true });
}
};
I've looked at the code several times but have no idea why he's doing it more and more often
client.on('interactionCreate', async interaction => {
if (!interaction.isStringSelectMenu()) return;
const selected = await interaction.values.join(', ');
const spielersucheerweitertEmbedfertig = new EmbedBuilder()
.setTitle(`${ginputdata}`)
.setColor('#00ff0c')
.setDescription(stripIndents`Spiel: \`${sinputdata}\`
Plattform: \`${selected}\``)
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp();
//executed when the button with the buttonanfrage custom ID is clicked
await interaction.channel.send({ embeds: [spielersucheerweitertEmbedfertig] });
return await interaction.update({ content: '**Spielersuche wurde erfolgreich Angefragt!**', components: [] });
});
});
//This block is executed when the function is run
await interaction.channel.send({ embeds: [spielersucheerweitertEmbed], components: [buttonsa] });
return await interaction.reply({ content: 'Spielersuche Embed wurde versendet!', ephemeral: true });
}
The issue you are experiencing is caused by the fact that both of these blocks of code are being executed, which is resulting in the same message and update being sent multiple times.
So you have 2 options:
Remove the second block of code that sends the message and updates
the interaction. This will prevent the message and update from being
sent multiple times.
Add a flag to track whether or not the message and update have
already been sent. You can then check the flag before sending the
message and update to ensure that they are only sent once.
I'm trying to code a discord bot in js to code a bot for school project.
But when I play my code it write that error. I don't understand how it happens. And i didn't had that error few times ago.It may be because I changed a command (SlashCommandBuilder), but i don't really understand.
Can u help me fix it pls? :)
const Discord = require("discord.js");
const { SlashCommandBuilder } = require("#discordjs/builders");
const { GiveawaysManager } = require('discord-giveaways');
const Canvas = require('canvas');
const Client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.DIRECT_MESSAGES,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS
]
});
const prefix = "botto ";
const data1 = new SlashCommandBuilder()
.setName("ping")
.setDescription("ping un utilisateur")
.addUserOption(option => option
.setName("utilisateur")
.setDescription("utilisateur a ping")
.setRequired(false));
const data2 = new SlashCommandBuilder()
.setName("clear")
.setDescription("delete un message")
.addIntegerOption(option => option
.setName("number")
.setDescription("nombre de message a clear")
.setRequired(true)
);
const dataGiveaway = new SlashCommandBuilder()
.setName("giveaway")
.setDescription("lancer un giveaway")
.addStringOption(option => option
.setName("duration")
.setDescription("Duration of the giveaway in d/days(jour) + hrs/h(heure) + m(minute) + s(second) or time in ms")
.setRequired(true)
)
.addIntegerOption(option => option
.setName("winners")
.setDescription("nombre de winners")
.setRequired(true)
)
.addStringOption(option => option
.setName("prize")
.setDescription("prix du giveaway")
.setRequired(true)
);
const giveawayReroll = new SlashCommandBuilder ()
.setName("reroll")
.setDescription("choisi un nouveau gagnant du giveaway")
.addStringOption(option => option
.setName("message_id")
.setDescription("id du message a reroll")
.setRequired(true)
);
const giveawayEdit = new SlashCommandBuilder ()
.setName("edit")
.setDescription("edit un giveaway")
.addStringOption(option => option
.setName("message_id")
.setDescription("id du giveaway a edit")
.setRequired(true)
)
.addStringOption(option => option
.setName("duration")
.setDescription("ajoute du temps en y/d/h/m/s")
.setRequired(true)
)
.addIntegerOption(option => option
.setName("winners")
.setDescription("nouveau nombre de winners")
.setRequired(true)
)
.addStringOption(option => option
.setName("prize")
.setDescription("new prize of the giveaway")
.setRequired(true)
);
const giveawayEnd = new SlashCommandBuilder()
.setName("end")
.setDescription("end a giveaway")
.addStringOption(option => option
.setName("message_id")
.setDescription("id du giveaway a edit")
.setRequired(true)
);
const manager = new GiveawaysManager(Client, {
storage: './giveaways.json',
default: {
botsCanWin: false,
embedColor: '#FF0000',
embedColorEnd: '#000000',
reaction: '🎉'
}
});
Client.on("ready", async () => {
Client.application.commands.create(data1);
Client.application.commands.create(data2);
Client.guilds.cache.get("971763992152395858").commands.create();
//supprimer une commande:
await Client.application.commands.fetch();
//Client.application.commands.cache.get("id command").delete();
Client.application.commands.cache.map(command => {
command.delete();
});
console.log("bot opérationnel");
});//log + create command '/'
Client.on("messageCreate", message => {
if (message.author.bot) return;
if (message.content === prefix + "tg") {
const embed = new Discord.MessageEmbed()
.setColor("#00A2DB")
.setTitle("ENFIIIIIIIIINNNNNNN!!!!!!!")
.setURL("https://discord.js.org/")
.setAuthor("Mighty jo", "https://i.imgur.com/AfFp7pu.png", "https://google.com/")
.setDescription("Y a pas mieux comme bot tema les commandes")
.setThumbnail("https://images3.alphacoders.com/111/1116286.jpg")
.addField("**__botto help__**", "Affiche la liste des commandes")
.addField("**__botto ping__**", "Renvoie pong")
.addField("**__Quoi ?__**", "renvoie tg toi")
.setImage("https://images3.alphacoders.com/111/1116286.jpg")
.setTimestamp()
.setFooter("Ce bot appartient a jojo92#1263", "https://www.fredzone.org/wp-content/uploads/2022/01/Sukuna-Jujutsu-Kaisen.jpg.webp");
message.channel.send({ embeds: [embed] });
}
});//embed
Client.on("messageCreate", async message => {
if(message.content === "Quoi ?"){
message.reply("tg toi");
}
/*else if(message.author.id == "220148991663407104"){
message.reply("tg tu sers a rien");
}*/
else if(message.author.id == "687979793052073995" && message.content.startsWith("Salut")){
message.reply("Bonjour maitre");
}
});//tg toi
Client.on("messageCreate", message => {
if (message.author.bot) return;
if(message.content === prefix + "ping"){
message.reply("botto pong");
}
else if(message.content === prefix + "help"){
message.channel.send("||T'as cru fréro||");
}
});//ping + help
Client.on("interactionCreate", interaction => {
if(interaction.isCommand()){
if(interaction.commandName === "ping"){
let user = interaction.options.getUser("utilisateur");
if (user != undefined){
interaction.reply("<#" + user.id + ">");
}
else {
interaction.reply("<#220148991663407104>");
}
}
/*else if(interaction.commandName === "help"){
interaction.reply("pong");
}*/
}
});// '/ping' command
Client.on("guildMemberAdd", async member => {
console.log("un membre est arrivé");
member.roles.add("973997039002193980");
var canvas = Canvas.createCanvas(1000,300);
ctx = canvas.getContext("2d");
var background = await Canvas.loadImage("./joinimg_demo.png");
ctx.drawImage(background, 0, 0, 1000, 300);
ctx.beginPath();
ctx.arc(150, 150, 110, 0, Math.PI * 2);
ctx.closePath();
ctx.clip();
var avatar = await Canvas.loadImage(member.user.displayAvatarURL({format: "png"}));
ctx.drawImage(avatar, 40, 40, 220, 220);
const embedBienvenue = new Discord.MessageEmbed()
.setTitle("**Ho ! Un nouveau membre !**")
.setDescription(":tada: Bienvenue <#" + member.id + "> :tada:")
.setImage('attachment://welcome.png');
var attachment = new Discord.MessageAttachment(canvas.toBuffer(), "welcome.png");
Client.channels.cache.get("973534330427170826").send({embeds: [embedBienvenue], files: [attachment]});
});//Message arrivée d'un nouveau membre
Client.on("guildMemberRemove", (member) => {
console.log("un membre est parti");
Client.channels.cache.get("973534330427170826").send("<#" + member.id + "> Dégage batard");
});//message expulsion d'un membre
Client.on("messageCreate", message => {
if(message.content === "bouton") {
var row = new Discord.MessageActionRow()
.addComponents(new Discord.MessageButton()
.setCustomId("bouton1")
.setLabel("appuie batard")
.setStyle("DANGER")
.setEmoji("🍆")
).addComponents(new Discord.MessageButton()
.setLabel("doc discord35")
.setStyle("LINK")
.setEmoji("🤤")
.setURL("https://fr.wikihow.com/cacher-une-%C3%A9rection")
);
message.channel.send({content: "message bouton", components: [row]});
}
});//bouton message avec interaction
Client.on("interactionCreate", interaction => {
if(interaction.isButton()) {
if(interaction.customId === "bouton1"){
interaction.reply("pk t'appuyé t'es un chien?");
}
}
});//interaction du bouton
Client.on("messageCreate", message => {
if(message.author.bot) return;
var row = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId("select")
.setPlaceholder("Select option")
.addOptions([
{
label: "premiere option",
description: "decrit 1",
value: "option1"
},
{
label: "option2",
description: "decrit2",
value: "2option"
}
])
);
if(message.content === prefix + "menu"){
message.channel.send({content: "menu de selection", components: [row]});
}
});//menu de selection
Client.on("interactionCreate", interaction => {
if(interaction.isSelectMenu()){
if(interaction.customId === "select"){
console.log(interaction.values);
if(interaction.values == "option1"){
interaction.reply({content: "vous avez choisi l'option 1", ephemeral: true});
}
else if(interaction.values == "2option"){
interaction.reply({content: "vous avez choisi l'option 2", ephemeral: true});
}
}
}
});//menu de selection
Client.on("interactionCreate", interaction => {
if(interaction.isCommand()){
if(interaction.commandName === "clear"){
var number = interaction.options.getInteger("number");
if(number >= 1 && number <= 100){
interaction.channel.bulkDelete(number);
interaction.reply({content: number + "messages supprimés", ephemeral: true});
}
else {
interaction.reply({content: "le nombre de message supprimé doit etre compris entre 1 et 100"});
}
}
}
});//commande /clear
Client.on("messageCreate", message => {
if(message.content === "giveaway") {
var authorId = message.author.id
var row = new Discord.MessageActionRow()
.addComponents(new Discord.MessageButton()
.setCustomId("bouton2")
.setLabel("appuie batard")
.setStyle("DANGER")
.setEmoji("🍆")
).addComponents(new Discord.MessageButton()
.setLabel("doc discord35")
.setStyle("LINK")
.setEmoji("🤤")
.setURL("https://fr.wikihow.com/cacher-une-%C3%A9rection")
);
message.channel.bulkDelete(1);
message.channel.send({content: "message bouton", components: [row]});
}
});//bouton giveaway
Client.on("interactionCreate", interaction => {
var row2 = new Discord.MessageActionRow()
.addComponents(new Discord.MessageButton()
.setCustomId("bouton3")
.setLabel("appuie batard")
.setStyle("DANGER")
.setEmoji("🍆")
).addComponents(new Discord.MessageButton()
.setLabel("doc discord35")
.setStyle("LINK")
.setEmoji("🤤")
.setURL("https://fr.wikihow.com/cacher-une-%C3%A9rection")
);
if(interaction.isButton()) {
if(interaction.customId === "bouton2"){
interaction.channel.bulkDelete(1);
interaction.channel.send({content: "message bouton", components: [row2]});
}
}
if(interaction.isButton()) {
if(interaction.customId === "bouton3"){
interaction.channel.bulkDelete(1);
interaction.channel.send("pk t'appuyé t'es un chien?");
}
}
});//interaction du bouton giveaway
Client.giveawaysManager = manager;
Client.on("interactionCreate", interaction => {
const ms = require("ms");
if(interaction.isCommand() && interaction.commandName === 'giveaway') {
const duration = interaction.options.getString('duration');
const winnerCount = interaction.options.getInteger('winners');
const prize = interaction.options.getString('prize');
Client.giveawaysManager.start(interaction.channel, {
duration: ms(duration),
winnerCount,
prize
}).then();
// And the giveaway has started!
}
});//create giveaway
Client.on('interactionCreate', (interaction) => {
if (interaction.isCommand() && interaction.commandName === 'reroll') {
const messageId = interaction.options.getString('message_id');
Client.giveawaysManager.reroll(messageId).then(() => {
interaction.channel.send('Success! Giveaway rerolled!');
}).catch((err) => {
interaction.channel.send(`An error has occurred, please check and try again.\n\`${err}\``);
});
}
});//reroll
Client.on('interactionCreate', (interaction) => {
if (interaction.isCommand() && interaction.commandName === 'edit') {
const ms = require('ms');
const duration = interaction.options.getString('duration');
const newWinnerCount = interaction.options.getInteger('winners');
const newPrize = interaction.options.getString('prize');
const messageId = interaction.options.getString('message_id');
Client.giveawaysManager.edit(messageId, {
addTime: ms(duration),
newWinnerCount,
newPrize
}).then(() => {
interaction.channel.send('Success! Giveaway updated!');
}).catch((err) => {
interaction.channel.send(`An error has occurred, please check and try again.\n\`${err}\``);
});
}
});//edit giveaway
Client.on('interactionCreate', (interaction) => {
if (interaction.isCommand() && interaction.commandName === 'end') {
const messageId = interaction.options.getString('message_id');
Client.giveawaysManager.end(messageId).then(() => {
interaction.channel.send('Success! Giveaway ended!');
}).catch((err) => {
interaction.channel.send(`An error has occurred, please check and try again.\n\`${err}\``);
});
}
});//end giveaway
Client.login("bot login ");
Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'name')
at transformCommand (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\discord.js\src\managers\ApplicationCommandManager.js:208:21)
at create (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\discord.js\src\managers\ApplicationCommandManager.js:118:30)
at <anonymous> (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\index.js:102:60)
at emit (node:events:527:28)
at triggerClientReady (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:17)
at checkShardsReady (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\discord.js\src\client\websocket\WebSocketManager.js:367:10)
at <anonymous> (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\discord.js\src\client\websocket\WebSocketManager.js:189:14)
at emit (node:events:527:28)
at checkReady (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\discord.js\src\client\websocket\WebSocketShard.js:475:12)
at onPacket (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\discord.js\src\client\websocket\WebSocketShard.js:447:16)
at onMessage (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at onMessage (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\ws\lib\event-target.js:199:18)
at emit (node:events:527:28)
at receiverOnMessage (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\ws\lib\websocket.js:1160:20)
at emit (node:events:527:28)
at dataMessage (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\ws\lib\receiver.js:528:14)
at getData (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\ws\lib\receiver.js:446:17)
at startLoop (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\ws\lib\receiver.js:148:22)
at _write (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\ws\lib\receiver.js:83:10)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at Writable.write (node:internal/streams/writable:334:10)
at socketOnData (c:\Users\hayot\OneDrive - Efrei\KTS Bot\Développement\Jonathan\BOTTOK-KUN\node_modules\ws\lib\websocket.js:1254:35)
at emit (node:events:527:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Readable.push (node:internal/streams/readable:228:10)
at onStreamRead (node:internal/stream_base_commons:190:23)
at callbackTrampoline (node:internal/async_hooks:130:17)
It's ok. It was really the fact that i changed my command i just create them back and it works.
Client.guilds.cache.get("971763992152395858").commands.create(giveawayEdit);
Client.guilds.cache.get("971763992152395858").commands.create(giveawayEnd);
Client.guilds.cache.get("971763992152395858").commands.create(giveawayReroll);
Client.guilds.cache.get("971763992152395858").commands.create(dataGiveaway);
I'm trying to make a ticket system, that when I click on the button, it changes the channel category and removes the member's permission to see it. When I click the button, it changes the category but doesn't change the channel's permission. I've already looked in the docs, and I haven't found anything.
the error:
C:\Users\whash\OneDrive\Documentos\optipc_bot_beta_sem_erro\events\ticket\suporte.js:187
interaction.channel.permissionOverwrites(subTicketSuporte.userId, {deny: Permissions.FLAGS.VIEW_CHANNEL})
^
TypeError: interaction.channel.permissionOverwrites is not a function
at Client.<anonymous> (C:\Users\whash\OneDrive\Documentos\optipc_bot_beta_sem_erro\events\ticket\suporte.js:187:29)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Database:
my code:
const {
MessageActionRow,
MessageButton,
MessageEmbed,
MessageSelectMenu,
Permissions,
} = require("discord.js");
const firebase = require("firebase");
const db = firebase.database();
const client = require("../../index");
client.on("interactionCreate", async (interaction) => {
if (interaction.isCommand()) return;
interaction.deferUpdate();
// ROWS //
const rowDelChannel = new MessageActionRow().addComponents(
new MessageButton()
.setStyle("DANGER")
.setLabel("🗑 | Deletar canal")
.setCustomId("delChannel")
);
const rowDelMessage = new MessageActionRow().addComponents(
new MessageButton()
.setStyle("DANGER")
.setLabel("🗑 | Deletar mensagem")
.setCustomId("delMessage")
);
const rowArchiveThread = new MessageActionRow().addComponents(
new MessageButton()
.setStyle("DANGER")
.setLabel("📨 | Arquivar thread")
.setCustomId("archiveThread")
);
const rowArchiveChannel = new MessageActionRow().addComponents(
new MessageButton()
.setStyle("DANGER")
.setLabel("📨 | Arquivar canal")
.setCustomId("archiveChannel")
);
// EMBEDS //
let embedOptions = new MessageEmbed()
.setTitle("🔒 | Opções do ticket")
.setDescription(
'Olá, bem vindo a aba de suporte! Caso queira fechar o ticket, clique em "arquivar" ou "deletar".'
)
.setColor("GREY")
.setFooter("A optiPC agradece sua atenção.", interaction.guild.iconURL());
let subTicketSuporte = await db.ref(`Ticket/Arquivado/${interaction.user.id}`).once("value");
subTicketSuporte = subTicketSuporte.val();
// PAINEL DE SUPORTE//
if (interaction.customId === "OPENSUPORTE") {
// DATABASE //
let ticketSuporte = await db.ref(`Ticket/Suporte`).once("value");
ticketSuporte = ticketSuporte.val();
//var subTicketSuporte = await db.ref(`Ticket/Arquivado/${interaction.user.id}`).once("value");
// subTicketSuporte = subTicketSuporte.val();
if (!ticketSuporte) ticketSuporte = {};
if (!subTicketSuporte) subTicketSuporte = {};
// salvando contador
if (!ticketSuporte.contador) {
db.ref(`Ticket/Suporte`).set({
contador: parseInt(1),
});
} else {
db.ref(`Ticket/Suporte`).update({
contador: ticketSuporte.contador + parseInt(1),
});
}
// salvando o ID do user na DB
if (!subTicketSuporte.userId) {
db.ref(`Ticket/Arquivado/${interaction.user.id}`).set({
userId: interaction.user.id
});
}
// configurando o canal do ticket
let canalSuporte = await interaction.guild.channels.create(
`❔▏suporte_${ticketSuporte.contador}`,
{
parent: "915975240541171813",
type: "GUILD_TEXT",
permissionOverwrites: [
{
id: interaction.guild.id,
deny: [Permissions.FLAGS.VIEW_CHANNEL],
},
{
id: interaction.user.id,
allow: [
Permissions.FLAGS.VIEW_CHANNEL,
Permissions.FLAGS.SEND_MESSAGES,
],
},
],
}
);
await canalSuporte.send({
embeds: [embedOptions],
components: [rowDelChannel, rowArchiveChannel],
});
interaction.followUp({
content: `✅ Ticket criado com sucesso! Por favor, vá até ${canalSuporte}.`,
ephemeral: true,
});
/*
// configurando thread
const threadSuporte = await interaction.channel.threads.create({
name: `❔▏suporte_${counterSuporte.contador}`,
autoArchiveDuration: 60,
// type: 'GUILD_PRIVATE_THREAD',
reason: 'Thread para suporte.'
});
if (threadSuporte.joinable) await threadSuporte.join();
await threadSuporte.members.add('840983211458428928');
await threadSuporte.members.add('550978800952016896');
await threadSuporte.members.add('518517142656647208');
await threadSuporte.members.add('639856950368010240');
// ARQUIVAR THREAD //
if (interaction.customId === "archiveThread") {
let permicaoNecessaria = Permissions.FLAGS.BAN_MEMBERS;
if (!interaction.member.permissions.has(permicaoNecessaria))
return interaction.followUp({
content: "Você não possui permissão para arquivar o ticket!",
ephemeral: true,
});
await threadSuporte.setArchived(true); // archived
}
}
*/
}
// ROW CONFIG
if (interaction.customId === "delChannel") {
let permicaoNecessaria = Permissions.FLAGS.BAN_MEMBERS;
if (!interaction.member.permissions.has(permicaoNecessaria))
return interaction.followUp({
content: "Você não possui permissão para fechar o ticket!",
ephemeral: true,
});
interaction.channel.delete();
}
if (interaction.customId === "delMessage") {
let permicaoNecessaria = Permissions.FLAGS.BAN_MEMBERS;
if (!interaction.member.permissions.has(permicaoNecessaria))
return interaction.followUp({
content: "Você não possui permissão para fechar o ticket!",
ephemeral: true,
});
interaction.message.delete();
}
if (interaction.customId === "archiveChannel") {
console.log("a") // a
let permicaoNecessaria = Permissions.FLAGS.BAN_MEMBERS;
if (!interaction.member.permissions.has(permicaoNecessaria))
return interaction.followUp({
content: "Você não possui permissão para arquivar o ticket!",
ephemeral: true,
});
await interaction.channel.setParent("915985254127370240");
interaction.channel.permissionOverwrites(subTicketSuporte.userId, {deny: Permissions.FLAGS.VIEW_CHANNEL})
}
});
In fact, GuildChannel#permissionOverwrites is not a function
It's a property that returns PermissionOverwriteManager
I suggest you to use
interaction.channel.permissionOverwrites.edit(subTicketSuporte.userId, { "VIEW_CHANNEL": false })
And that should be it
Docs Source
GuildChannel#permissionOverwrites is a PermissionOverwriteManager. Use .set on it instead:
interaction.channel.permissionOverwrites.set([{
deny: [Permissions.FLAGS.VIEW_CHANNEL],
id: subTicketSuporte.userId,
type: "member"
}])