Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I made a command but bot is spamming after command is executed to a channel.
Could you please help me out? It's a simple mistake but I am confused right now. I tried many things..
Code:
client.on("message", (message) => {
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (message.channel.id == `912767631344423032`) {
if (command === "sinfo")
const server = new Discord.MessageEmbed()
.setColor("#6C8A9D")
.setAuthor(message.author.tag, message.author.avatarURL())
.setTitle("Server Info!")
.addFields(
{
name: "Όνομα Server:",
value: `${message.guild.name}`,
inline: true,
},
{
name: "Δημιουργήθηκε στις:",
value: `${message.guild.createdAt}`,
inline: true,
},
{ name: "Server ID:", value: `${message.guild.id}`, inline: true },
{
name: "Server Owner:",
value: `${message.guild.owner}`,
inline: true,
},
{
name: "Server Developer:",
value: `<�>`,
inline: true,
},
{
name: "Τόπος καταγωγής Server:",
value: `${message.guild.region}`,
inline: true,
},
{
name: "Αληθινά άτομα:",
value: `${message.guild.createdAt}`,
inline: true,
},
{
name: "Επίπεδο Επαλίθευσης:",
value: `${message.guild.verificationLevel}`,
inline: true,
}
)
.setFooter("Created and Developed by Tana#6969 ❤️")
.setTimestamp();
message.channel.send(server);
}
});
Are you missing the { } for this if:
if (command === "sinfo")
Related
I was working on a project where we can create a form like google forms and get responses from users, and then we can view those responses in the admin panel.
My English is not that good I tried my best to explain the problem!
I am using MERN Stack so I was tucked into a problem related to how to save the questions and record the responses in MongoDB in a standard way in objects and arrays.
currently I added this as a form model :
const formSchema = new Schema({
usererId: { type: Schema.Types.ObjectId, ref: 'User' },
title: { type: String, required: true },
description: { type: String},
username: { type: String, required: true },
password: { type: String, required: true },
isEnabled: { type: Boolean, default: true },
expiresOn: { type: Date, default: null },
fields: [
{
title: { type: String, required: true },
placeholder: { type: String, required: false },
type: { type: String, required: true },
required: { type: Boolean, required: true },
options: [
{
title: { type: Object, required: true },
priority: { type: Number, default: 0, required: true }
}
],
priority: { type: Number, required: true, default: 0 },
enabled: { type: Boolean, default: true, required: true }
}
],
}, {
timestamps: true
})
and form responses :
const formResponseSchema = new Schema({
digitalFormId: { type: Schema.Types.ObjectId, ref: 'Form' },
isVerified: { type: Boolean, default: false },
formResponse: [{ type: Object, required: true }],
}, {
timestamps: true
})
I don't know if this approach is good, I myself like it's not like a standard one and I m confused, Someone please tell me how should I do it and what is the perfect way of doing it,
If you have a problem understanding what I am saying just tell me simply how a google form works in the backend from API view, like question ID server-side validation and response submit, that time what type of request is sent to the server, something like this !
If you don't mind please take out some time and write a brief approach of what type of Schema should I use and how should I save them.
Something more important is what approach to use while checking the form response data coming from the client to validate on server-side means on express API, like {questionId: idofquestion, value:'Value of the response of the particular question'}, later checking the question label and all other things with the form questions and all validation rules to fetch from them and check, but I don't know how to do that It's really confusing for me.
Thanks in Advance for the help! ❤️
I'd like to know if it's possible to create a slash command in the discord.js bot with one of the options receiving the type as an array of options, likely the following:
export enum LabTypes {
Simulated = "SIMULATED",
Odyssey = "ODYSSEY",
Guided = "GUIDED",
CloudCity = "CLOUD_CITY",
CommandCenter = "COMMAND_CENTER",
Embeded = "EMBEDED"
}
And
{
name: "type",
description: "Enter the HOL type",
type: this.commandsType.LAB_TYPES,
required: true,
}
I would like in the type parameter, the LabTypes options to be suggested.
Resolved by including the choices on my question.
Here's the code:
{
name: "type",
description: "Enter the HOL type",
type: this.commandsType.STRING,
required: true,
choices: [
{
name: "GUIDED",
value: "GUIDED"
},
{
name: "ODYSSEY",
value: "ODYSSEY"
},
{
name: "SIMULATED",
value: "SIMULATED"
},
{
name: "CLOUD CITY",
value: "CLOUD_CITY"
},
{
name: "COMMAND CENTER",
value: "COMMAND_CENTER"
},
{
name: "EMBEDED",
value: "EMBEDED"
},
]
}
Simple as that.
References: https://canary.discord.com/developers/docs/interactions/slash-commands
I am having an issue were I need to generate a form from a schema and have fields dependent on each other such as enabled/disable show/hide etc.
my schema looks something like this.
contractorInformation: {
title: "ContractorInformation",
type: "object",
properties: {
contractorName: {
title: "Contractor Name",
type: "string",
ui: "input",
constraints: {
required: true
}
},
contractorFavouriteAnimal: {
title: "Contractor Favourite Animal",
type: "string",
ui: "input",
constraints: {},
dependencies: {
disabled: true,
watching: "contractorName"
// //disabled={!fullName || fullName.length === 0 || errors.fullName}
}
},
contractorEmail: {
title: "Contractor Email",
type: "string",
ui: "input",
constraints: {
common: 10
}
}
}
},
agencyInformation: {
title: "ContractorInformation",
type: "object",
properties: {
contractorName: {
title: "Contractor Name",
type: "string",
ui: "input",
constraints: {
required: true,
minLength: 3,
maxLength: 5
},
dependencies: {
disabled: true,
watching: "agencyName"
}
}
}
}
}
const watchThese = watch()
would allow me to watch everything but if I wanted to change this field from disabled to enabled I could use
<input disabled={!watchThese || watchThese.length === 0 || watchThese.fullName}/>
which works but is obviously triggered by every field.
How could I generate a dynamic watch()/useWatch() from a schema and be able to access the specific dependencies I need to enable/disable the input.
Any help would be gratefully received.
For future reference I solved it by using
export const FormField = () =>
{Object.entries(schema?.actions ?? {}).forEach(([key, value]) => value(watch(key)));
return (<div></div>)}
and update schema to match.
I have this thing that's going on in my BOT. with this code I get some info from the server the user is on:
if (command === `server`) {
message.react("🌐");
const owner = message.guild.owner.user.tag;
const embedServer = new Discord.MessageEmbed()
.setTitle(`**:books: Server Info: ${message.guild.name}**`)
.setDescription(`Some information about the server you're on.`)
.addFields(
{ name: ':person_raising_hand: ・ Member Count', value: message.guild.memberCount, inline: true },
{ name: ':calendar_spiral: ・ Creation Date', value: message.guild.createdAt, inline: true },
{ name: ':globe_with_meridians: ・ Server Region', value: (message.guild.region).toUpperCase(), inline: true },
{ name: ':crown: ・ Server Owner', value: owner, inline: true },
)
.setFooter(`${botnv}`)
.setColor('#f04747')
message.channel.send(embedServer).catch(err => message.channel.send(":warning: Error!"));
};
And it works just fine when on my private server, but once i test it on one where the BOT can't see who the owner is, it just crashes. I want it to send a message saying it couldn't find them. Everything I've tried hasn't worked. if(!user) return under the const doesn't work, .catch(err) doesn't work aswell. I'm stuck.
You should check if the owner exists first, rather than getting properties on something that is potentially undefined.
I would suggest using this instead:
const owner = message.guild.owner;
if(!owner) {
console.log("Unable to find owner");
} else {
let tag = owner.user.tag;
}
So to integrate this into your code you could do something like this:
if (command === `server`) {
message.react("🌐");
const owner = message.guild.owner;
if(owner) {
const embedServer = new Discord.MessageEmbed()
.setTitle(`**:books: Server Info: ${message.guild.name}**`)
.setDescription(`Some information about the server you're on.`)
.addFields(
{ name: ':person_raising_hand: ・ Member Count', value: message.guild.memberCount, inline: true },
{ name: ':calendar_spiral: ・ Creation Date', value: message.guild.createdAt, inline: true },
{ name: ':globe_with_meridians: ・ Server Region', value: message.guild.region.toUpperCase(), inline: true },
{ name: ':crown: ・ Server Owner', value: owner.user.tag, inline: true },
)
.setFooter(`${botnv}`)
.setColor('#f04747')
message.channel.send(embedServer).catch(err => message.channel.send(":warning: Error!"));
} else {
message.channel.send("Unable to find owner");
}
};
Also, one other thing is that you shouldn't need to have brackets around message.guild.region. :)
You can use try/catch statement & get error & send message to channel
if (command === `server`) {
message.react("🌐");
try {
const owner = message.guild.owner.user.tag;
const embedServer = new Discord.MessageEmbed()
.setTitle(`**:books: Server Info: ${message.guild.name}**`)
.setDescription(`Some information about the server you're on.`)
.addFields({
name: ':person_raising_hand: ・ Member Count',
value: message.guild.memberCount,
inline: true
}, {
name: ':calendar_spiral: ・ Creation Date',
value: message.guild.createdAt,
inline: true
}, {
name: ':globe_with_meridians: ・ Server Region',
value: (message.guild.region).toUpperCase(),
inline: true
}, {
name: ':crown: ・ Server Owner',
value: owner,
inline: true
}, )
.setFooter(`${botnv}`)
.setColor('#f04747')
message.channel.send(embedServer);
} catch (error) {
console.log(error); //Console Log Error
return message.channel.send(":warning: Error!");
};
};
Learn more about try/catch here
I am trying to return only the values in an array. I managed to solve this a few months ago on a different project but I have forgotten how.
Here is my current query and the result.
database.find({todo: {$exists: true}},{projection:{_id: 0}}).toArray((error,data) => {
console.log(data);
res.json(data);
});
[
{
todo: {
id: '30a508fbfb8a51d2784920c2d6b7468c',
text: 'testing',
completed: false
}
},
{
todo: {
id: 'dedf6f6a850f7fef02566de027e74416',
text: 'testing',
completed: false
}
}
]
I would like it to return only the values in the Todo array as seen below. What do I need to add in the projection field to make this happen?
[
{
id: '30a508fbfb8a51d2784920c2d6b7468c',
text: 'testing',
completed: false
},
{
id: 'dedf6f6a850f7fef02566de027e74416',
text: 'testing',
completed: false
}
]
Thank you,
I was able to figure it out. Turns out I was using the wrong function.
If there is anyone looking for this solution you want to use distinct and not projections.
database.distinct('todo', function(err, data) {
console.log(data);
});
This resulted in the following below which is what I was needing.
[
{
id: '30a508fbfb8a51d2784920c2d6b7468c',
text: 'testing',
completed: false
},
{
id: 'dedf6f6a850f7fef02566de027e74416',
text: 'testing',
completed: false
}
]
Thanks,