caesar
caesar
SIASapphire - Imagine a framework
Created by caesar on 1/29/2023 in #discordjs-support
Giveaway ends in "active time changes"
No description
26 replies
SIASapphire - Imagine a framework
Created by caesar on 12/9/2022 in #discordjs-support
Getting info from JSON
const counterName = interaction.guild.channels.cache
.filter(channel => channel.name.startsWith("ticket_"))
.map(channel => parseInt(channel.name.split("_")[1]))
.sort();

const fs = require('fs');
const path = require('path');

const data = fs.readFileSync(path.resolve(__dirname, './tickets.json'));
const tickets = JSON.parse(data);

const ticketId = ((counterName[counterName.length - 1] || 0) + 1).toString().padStart(4, '0')
tickets.push([ticketId]);


fs.writeFileSync(path.resolve(__dirname, './tickets.json'), JSON.stringify(tickets, null, 2));


const createdChannel = await interaction.guild.channels.create("ticket_" + ((counterName[counterName.length - 1] || 0) + 1).toString().padStart(4, '0'), {`

const counterName = interaction.guild.channels.cache
.filter(channel => channel.name.startsWith("ticket_"))
.map(channel => parseInt(channel.name.split("_")[1]))
.sort();

const fs = require('fs');
const path = require('path');

const data = fs.readFileSync(path.resolve(__dirname, './tickets.json'));
const tickets = JSON.parse(data);

const ticketId = ((counterName[counterName.length - 1] || 0) + 1).toString().padStart(4, '0')
tickets.push([ticketId]);


fs.writeFileSync(path.resolve(__dirname, './tickets.json'), JSON.stringify(tickets, null, 2));


const createdChannel = await interaction.guild.channels.create("ticket_" + ((counterName[counterName.length - 1] || 0) + 1).toString().padStart(4, '0'), {`

Hello, this is my code for countering ticket channels, like 0001, 0002, 0003 etc. but i have one simple problem, how i can getting info from tickets.json? Because now i getting info from channel name, but its bad for me, because if i close ticket and delete it, the function channel.name.starsWith("ticket_") it will make the next ticket be 0001 again because there is no channel named ticket_0001 etc. I am quite inexperienced in this, so if someone could please tell me what to do, I would be grateful, thanks everyone! I made this using the tutorials but I'm bad at programming so I don't know how to do it.
3 replies