Alexcitten
Alexcitten
Explore posts from servers
PPrisma
Created by Alexcitten on 7/7/2024 in #help-and-questions
Can't reach database server at localhost:5432
PostgreSQL 16, I'm implementing OpenAPI on Cloudfare Workers using TypeScript, I did an endpoint and it shows an error PrismaClientKnownRequestError: Invalid prisma.clientProfile.create() invocation: This request could not be understood by the server: {"type":"UnknownJsonError","body":{"code":"P6008","message":"Accelerate was not able to connect to your database. The underlying error is: Can't reach database server at localhost:5432\n\nPlease make sure your database server is running at localhost:5432."}} I don't understand what the error is because my seeding is working correctly, the whole database setup seems to be correct, next I will give more input from my app Endpoint:
import prisma from '../../prisma/prisma';
...
async handle(request: Request, env: any, context: any, data: Record<string, any>) {
const profileToCreate = data.body;

try {
const createdProfile = await prisma.clientProfile.create({
data: {
companyName: profileToCreate.companyName,
registeredOffice: profileToCreate.registeredOffice,
uniqueRegistrationCode: profileToCreate.uniqueRegistrationCode,
commercialRegisterNumber: profileToCreate.commercialRegisterNumber,
billingEmails: profileToCreate.billingEmails,
contactDetails: {
create: profileToCreate.contactDetails.map((contact: any) => ({
contactPerson: contact.contactPerson,
contactEmail: contact.contactEmail,
contactPhone: contact.contactPhone,
})),
},
},
});

return {
success: true,
result: createdProfile,
};
...
import prisma from '../../prisma/prisma';
...
async handle(request: Request, env: any, context: any, data: Record<string, any>) {
const profileToCreate = data.body;

try {
const createdProfile = await prisma.clientProfile.create({
data: {
companyName: profileToCreate.companyName,
registeredOffice: profileToCreate.registeredOffice,
uniqueRegistrationCode: profileToCreate.uniqueRegistrationCode,
commercialRegisterNumber: profileToCreate.commercialRegisterNumber,
billingEmails: profileToCreate.billingEmails,
contactDetails: {
create: profileToCreate.contactDetails.map((contact: any) => ({
contactPerson: contact.contactPerson,
contactEmail: contact.contactEmail,
contactPhone: contact.contactPhone,
})),
},
},
});

return {
success: true,
result: createdProfile,
};
...
schema:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema", "driverAdapters"]
engineType = "library"
}
...
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema", "driverAdapters"]
engineType = "library"
}
...
../../prisma/prisma:
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

const prismaClient = new PrismaClient({
datasources: {
db: {
url: 'prisma://accelerate.prisma-data.net/?api_key=KEY...',
},
},
}).$extends(withAccelerate());

export default prismaClient;
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

const prismaClient = new PrismaClient({
datasources: {
db: {
url: 'prisma://accelerate.prisma-data.net/?api_key=KEY...',
},
},
}).$extends(withAccelerate());

export default prismaClient;
.env: DIRECT_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres?schema=public" DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=apikey" When using endpoint, in my pgAdmin 4 database I see activity from connections, the correct link is connected to my database in Accelerate, but I get this error. my seed.ts, which works just fine:
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
const clientProfiles = [
{
companyName: '...',
registeredOffice: '...',
uniqueRegistrationCode: '...',
commercialRegisterNumber: '...',
billingEmails: ['..'],
contactDetails: {
create: [
{
contactPerson: 'J..',
contactEmail: '..',
contactPhone: '..',
},
{
contactPerson: '..',
contactEmail: '..',
contactPhone: '..',
},
],
},
},
{
companyName: '..',
registeredOffice: '..',
uniqueRegistrationCode: '..,
commercialRegisterNumber: '1.',
billingEmails: ['....', '..'],
contactDetails: {
create: [
{
contactPerson: '..n',
contactEmail: '...m',
contactPhone: '1...',
},
],
},
},
];

for (const clientProfile of clientProfiles) {
await prisma.clientProfile.create({
data: clientProfile,
});
}
...
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
const clientProfiles = [
{
companyName: '...',
registeredOffice: '...',
uniqueRegistrationCode: '...',
commercialRegisterNumber: '...',
billingEmails: ['..'],
contactDetails: {
create: [
{
contactPerson: 'J..',
contactEmail: '..',
contactPhone: '..',
},
{
contactPerson: '..',
contactEmail: '..',
contactPhone: '..',
},
],
},
},
{
companyName: '..',
registeredOffice: '..',
uniqueRegistrationCode: '..,
commercialRegisterNumber: '1.',
billingEmails: ['....', '..'],
contactDetails: {
create: [
{
contactPerson: '..n',
contactEmail: '...m',
contactPhone: '1...',
},
],
},
},
];

for (const clientProfile of clientProfiles) {
await prisma.clientProfile.create({
data: clientProfile,
});
}
...
Open to any discussion, I really want to get this fixed. Thank you!
4 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 11/26/2023 in #djs-questions
File Attachment
How do I attach my attachment in the embed after rank.build(), given that this embed is needed for my my-karma.js command? I mean when my command is called, it calls an embed from another file where everything is very connected. my-karma.js:
const { SlashCommandBuilder } = require("discord.js");
const { getMemberTotalKarma } = require("../../modules/member");

module.exports = {
data: new SlashCommandBuilder().setName("my-karma").setDescription("meow"),
async execute(interaction) {
await interaction.deferReply({
fetchReply: true,
deferReply: true,
})

const embed = await getMemberTotalKarma(interaction.member);

await interaction.editReply({
embeds: [embed]
})
}
}
const { SlashCommandBuilder } = require("discord.js");
const { getMemberTotalKarma } = require("../../modules/member");

module.exports = {
data: new SlashCommandBuilder().setName("my-karma").setDescription("meow"),
async execute(interaction) {
await interaction.deferReply({
fetchReply: true,
deferReply: true,
})

const embed = await getMemberTotalKarma(interaction.member);

await interaction.editReply({
embeds: [embed]
})
}
}
src/modules/member/controller.js:
...
const getMemberTotalKarma = async (memberDiscordId, interaction) => {
try {
...
if (gradationValue && gradationRole) {
await interaction.deferReply({
fetchReply: true,
deferReply: true,
})
...
const rank = new canvacord.Rank()
.setAvatar(img)
.setCurrentXP(karma)
.setRequiredXP(karmaNeededForNextRole)
.setProgressBar("#e523ff")
.setUsername(memberDiscordId.user.username)
.renderEmojis(true)
.setRank(karma, "kR", true)

rank.build()
.then(async buffer => {
const attachment = new AttachmentBuilder(buffer, { name: 'rank.png' })
return new EmbedBuilder()
.setColor(colors.primary)
.setDescription(`meow`)
.setImage(`attachment://${attachment.name}`);
});
}
return new EmbedBuilder().setColor(colors.primary).setDescription(`meow2`);
} catch (error) {
console.log(error);
return new EmbedBuilder().setColor(colors.danger).setDescription(`error`);
}
}
...
...
const getMemberTotalKarma = async (memberDiscordId, interaction) => {
try {
...
if (gradationValue && gradationRole) {
await interaction.deferReply({
fetchReply: true,
deferReply: true,
})
...
const rank = new canvacord.Rank()
.setAvatar(img)
.setCurrentXP(karma)
.setRequiredXP(karmaNeededForNextRole)
.setProgressBar("#e523ff")
.setUsername(memberDiscordId.user.username)
.renderEmojis(true)
.setRank(karma, "kR", true)

rank.build()
.then(async buffer => {
const attachment = new AttachmentBuilder(buffer, { name: 'rank.png' })
return new EmbedBuilder()
.setColor(colors.primary)
.setDescription(`meow`)
.setImage(`attachment://${attachment.name}`);
});
}
return new EmbedBuilder().setColor(colors.primary).setDescription(`meow2`);
} catch (error) {
console.log(error);
return new EmbedBuilder().setColor(colors.danger).setDescription(`error`);
}
}
...
3 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 1/16/2023 in #djs-questions
Checking bot permissions in a channel
Do it with permissions.has()?
6 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 1/14/2023 in #djs-questions
The button collector is not working, I'm doing something wrong
Code:
if (usdPricePerByteFormatted === 0) {
const confirmEmbedZero = new EmbedBuilder()
. . .

const yesZero = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Yes')
.setCustomId('yeschannel')
.setStyle(ButtonStyle.Success)
)
const noZero = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('No')
.setCustomId('nochannel')
.setStyle(ButtonStyle.Danger)
)
return interaction.editReply({
embeds: [confirmEmbedZero],
ephemeral: true,
components: [yesZero, noZero]
})
}

const filter = i => i.customId === 'yeschannel' && i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter })

collector.on("collect", async i => {
console.log('yea!!')
})
collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
if (usdPricePerByteFormatted === 0) {
const confirmEmbedZero = new EmbedBuilder()
. . .

const yesZero = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Yes')
.setCustomId('yeschannel')
.setStyle(ButtonStyle.Success)
)
const noZero = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('No')
.setCustomId('nochannel')
.setStyle(ButtonStyle.Danger)
)
return interaction.editReply({
embeds: [confirmEmbedZero],
ephemeral: true,
components: [yesZero, noZero]
})
}

const filter = i => i.customId === 'yeschannel' && i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter })

collector.on("collect", async i => {
console.log('yea!!')
})
collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
I do it in command file, not in interactionCreate
4 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 1/9/2023 in #djs-questions
Get all messages in channel
6 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 12/17/2022 in #djs-questions
Many slash commands with the same beginning
I want to make commands that start with the same name but have different sub-commands. Is this only possible via SlashCommandBuilder()? For my code structure is now
module.exports = {
name: "commandname",
category: "test",
options: [
{
name: 'namesubcommand',
description: 'description',
type: 1,
options: [
{
name: 'optionname',
description: 'second description',
type: 3,
required: true
}
]
}
],
. . .
module.exports = {
name: "commandname",
category: "test",
options: [
{
name: 'namesubcommand',
description: 'description',
type: 1,
options: [
{
name: 'optionname',
description: 'second description',
type: 3,
required: true
}
]
}
],
. . .
And with the same command names, obviously, it gives me Application command names must be unique, because I'm trying to specify the same name for several slash commands
3 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 12/16/2022 in #djs-questions
Types of options
Please tell me what each type is responsible for, give documentation on the types of options 3.options[0].options[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (9, 8, 7, 6, 5, 10, 3, 4, 11).
6 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 11/30/2022 in #djs-questions
when checking for the number of characters in the argument, I ran into a problem that the bot sends
when checking for the number of characters in the argument, I ran into a problem that the bot sends the error "not such a number of characters in the argument" anyway, even if everything is correct
const { ApplicationCommandOptionType, EmbedBuilder } = require('discord.js');

module.exports = {
name: "test",
usage: "/test",
options: [
{
name: 'option',
description: '43-symbol',
type: ApplicationCommandOptionType.String,
required: true
}
],
category: "test",
description: "test",
ownerOnly: false,
run: async (client, interaction, args) => {

await interaction.deferReply({ephemeral: true});

if(!interaction.options.getString("option").lenght !== 43) {
interaction.editReply({
content: `not 43`
})
} else {

const embed = new EmbedBuilder()
.setThumbnail(client.user.displayAvatarURL())
.addFields([
{name: `yay`, value: `${interaction.options.getString("option")}`}
])
.setColor('#FF8747')
.setFooter({
text: `test`,
iconURL: `${client.user.displayAvatarURL()}`
});

return interaction.reply({
embeds: [embed],
ephemeral: true
});
}
}
}
const { ApplicationCommandOptionType, EmbedBuilder } = require('discord.js');

module.exports = {
name: "test",
usage: "/test",
options: [
{
name: 'option',
description: '43-symbol',
type: ApplicationCommandOptionType.String,
required: true
}
],
category: "test",
description: "test",
ownerOnly: false,
run: async (client, interaction, args) => {

await interaction.deferReply({ephemeral: true});

if(!interaction.options.getString("option").lenght !== 43) {
interaction.editReply({
content: `not 43`
})
} else {

const embed = new EmbedBuilder()
.setThumbnail(client.user.displayAvatarURL())
.addFields([
{name: `yay`, value: `${interaction.options.getString("option")}`}
])
.setColor('#FF8747')
.setFooter({
text: `test`,
iconURL: `${client.user.displayAvatarURL()}`
});

return interaction.reply({
embeds: [embed],
ephemeral: true
});
}
}
}
5 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 8/4/2022 in #djs-questions
How send message to specific channel by channel id?
i will try interaction.channels.fetch("ID") but fetch is not defined
7 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 8/2/2022 in #djs-questions
Get all tags and ID's users in voice channel by channel ID
How to get list all peoples, which are connected to a specific channel? User tags and ID's
3 replies
DIAdiscord.js - Imagine an app
Created by Alexcitten on 6/29/2022 in #djs-questions
Is it possible now to interact with the automod mode on servers
4 replies