Duplicate Channels & Single Message

Hi, so I'm having an issue where the bot creates a channel twice (it's not supposed to do that) but in logs, it only acknowledges it as doing it once. Then, I'm having the issue where I want two messages sent to a channel separately, but they send together
10 Replies
d.js toolkit
d.js toolkit5d ago
meowmeow22
meowmeow22OP5d ago
const {
SlashCommandBuilder,
PermissionFlagsBits,
ChannelType,
ModalBuilder,
TextInputBuilder,
TextInputStyle,
ActionRowBuilder,
} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("asleep")
.setDescription("Open a ticket"),
async execute(interaction) {

const channel = await interaction.guild.channels.create({
name: `(?)${interaction.user.username}`,
type: ChannelType.GuildText,
parent: "1382014842948292608",
});


await channel.permissionOverwrites.set([
{
id: interaction.guild.roles.everyone.id,
deny: [PermissionFlagsBits.ViewChannel],
},
{
id: interaction.user.id,
allow: [PermissionFlagsBits.ViewChannel],
},
{
id: "1387344400715219025", // sock
allow: [PermissionFlagsBits.ViewChannel],
},
]);

const modal = new ModalBuilder()
.setCustomId(`asleepmodal|${channel.id}`)
.setTitle("Send your info");

const serverAdInput = new TextInputBuilder()
.setCustomId("serveradinput")
.setLabel("Server Ad")
.setStyle(TextInputStyle.Paragraph)
.setRequired(true);

const serverLinkInput = new TextInputBuilder()
.setCustomId("serverlinkinput")
.setLabel("Server Link")
.setPlaceholder("no vanity links")
.setStyle(TextInputStyle.Short)
.setRequired(true);

const firstRow = new ActionRowBuilder().addComponents(serverAdInput);
const secondRow = new ActionRowBuilder().addComponents(serverLinkInput);

modal.addComponents(firstRow, secondRow);

await interaction.showModal(modal);
},
};
const {
SlashCommandBuilder,
PermissionFlagsBits,
ChannelType,
ModalBuilder,
TextInputBuilder,
TextInputStyle,
ActionRowBuilder,
} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("asleep")
.setDescription("Open a ticket"),
async execute(interaction) {

const channel = await interaction.guild.channels.create({
name: `(?)${interaction.user.username}`,
type: ChannelType.GuildText,
parent: "1382014842948292608",
});


await channel.permissionOverwrites.set([
{
id: interaction.guild.roles.everyone.id,
deny: [PermissionFlagsBits.ViewChannel],
},
{
id: interaction.user.id,
allow: [PermissionFlagsBits.ViewChannel],
},
{
id: "1387344400715219025", // sock
allow: [PermissionFlagsBits.ViewChannel],
},
]);

const modal = new ModalBuilder()
.setCustomId(`asleepmodal|${channel.id}`)
.setTitle("Send your info");

const serverAdInput = new TextInputBuilder()
.setCustomId("serveradinput")
.setLabel("Server Ad")
.setStyle(TextInputStyle.Paragraph)
.setRequired(true);

const serverLinkInput = new TextInputBuilder()
.setCustomId("serverlinkinput")
.setLabel("Server Link")
.setPlaceholder("no vanity links")
.setStyle(TextInputStyle.Short)
.setRequired(true);

const firstRow = new ActionRowBuilder().addComponents(serverAdInput);
const secondRow = new ActionRowBuilder().addComponents(serverLinkInput);

modal.addComponents(firstRow, secondRow);

await interaction.showModal(modal);
},
};
this is the only command that creates a ticket but idk where the issue is ^
Amgelo
Amgelo5d ago
are you sure you don't have 2 instances of your bot running also you most likely want to listen for the submit and then create the channel, not the way around otherwise people can just spam the command or use it and then not submit any info
meowmeow22
meowmeow22OP5d ago
nope, there's only one instance i actually hadnt thought of that... ty Also, with the seprrate message thing how would i go about that?
module.exports = (client) => {
const { Events, MessageFlags } = require("discord.js");

client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isModalSubmit()) return;

console.log("modal sent:", interaction.customId);

if (!interaction.customId.startsWith("asleep|")) return;

const channelId = interaction.customId.split("|")[1];

const serverad = interaction.fields.getTextInputValue("serverad");
const serverlink = interaction.fields.getTextInputValue("serverlink");

const target = await interaction.client.channels
.fetch(channelId)
.catch(() => null);
if (!target || !target.isTextBased()) {
console.log("not a real channel..?");
return;
}

const Ad = await target.send({ content: `${serverad}` });
await Ad.pin().catch(() => null);


const Link = await target.send({ content: `${serverlink}`});
await Link.pin().catch(() => null);


await interaction.reply({
content: `modal sent to <#${channelId}>`,
flags: MessageFlags.Ephemeral,
});

console.log(`ticket message sent in ${channelId}`);
});
};
module.exports = (client) => {
const { Events, MessageFlags } = require("discord.js");

client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isModalSubmit()) return;

console.log("modal sent:", interaction.customId);

if (!interaction.customId.startsWith("asleep|")) return;

const channelId = interaction.customId.split("|")[1];

const serverad = interaction.fields.getTextInputValue("serverad");
const serverlink = interaction.fields.getTextInputValue("serverlink");

const target = await interaction.client.channels
.fetch(channelId)
.catch(() => null);
if (!target || !target.isTextBased()) {
console.log("not a real channel..?");
return;
}

const Ad = await target.send({ content: `${serverad}` });
await Ad.pin().catch(() => null);


const Link = await target.send({ content: `${serverlink}`});
await Link.pin().catch(() => null);


await interaction.reply({
content: `modal sent to <#${channelId}>`,
flags: MessageFlags.Ephemeral,
});

console.log(`ticket message sent in ${channelId}`);
});
};
everything else works fine with the exception of that
NyR
NyR5d ago
This is just how discord shows in ui, multiple messages sent by same user in quick succession are grouped together. Nothing you can do about it It's not one message, it still is a separate message. Just displayed under one username/nickname
meowmeow22
meowmeow22OP5d ago
Yeah, at first I thought it was just me looking at it wrong
No description
No description
meowmeow22
meowmeow22OP5d ago
But, no, they send together pin together
NyR
NyR5d ago
How are you sending this message? Can you show?
meowmeow22
meowmeow22OP5d ago
It uses this slash command's modal
meowmeow22
meowmeow22OP5d ago
Is this what you mean?
No description

Did you find this page helpful?