//slash command to echo
bot.on("ready", async () => {
bot.user.setPresence({ activities: [{ name: "Tedi", type: "WATCHING"}] });
console.log("bye");
const data = {
name: "echo",
description: "Echo your text",
options: [{
name: "text",
type: "STRING",
description: "The user input",
required: true,
}],
};
const command = await bot.guilds.cache.get('server id number')?.commands.create(data);
})
This is the error message I'm getting in heroku and I'm not sure what missing access means.
Thanks in advance!
This is a very common problem
You can go to the developer department
https://discord.com/developers/applications
Follow the pattern below
Step 1
Step 2
Then copy the following URL and paste it on the web page, then choose where you want to create the slash command, and that's it!
Related
I'm Currently Trying to get the user_id from the interaction.
This code will add command named 'test' that will give option 'testing' and when someone types '1' then it should show the channel_id that the command went from and also the user that did that command.
test.js :
module.exports = {
name: "test",
description: "example",
options: [
{
name: "testing",
description: "testing only.",
type: 3,
required: true,
},
],
async execute(_bot, say, interaction, args) {
let object1 = args[0].value;
if (object1 == '1') {
await say(interaction, 'Channel ID : ' + interaction.channel_id + '\nUser : '+ interaction.message.author.id);
}
else
{
return;
}
},
};
My Problem here that it's not getting the user.id in any way i have tried the following examples :
interaction.member.id;
interaction.user.id;
interaction.user_id;
interaction.member_id;
interaction.guildmember.id;
Noone of them works.
It should've been ;
interaction.member.user.id
Because it appeared in the log under member.
I wanted to ask how to create channels in discord.js 14 (i tried to researched but found nothing) I want to make a simple text channel! :)) Also, with the stuff i found, it worked ( no errors) it just didnt create anything / post errors in debug log
It's literally under Discord.js documentation. Please, next time before asking a question read the docs.
https://discord.js.org/#/docs/discord.js/main/general/welcome
guild.channels.create({
name: "hello",
type: ChannelType.GuildText,
parent: cat[0].ID,
// your permission overwrites or other options here
});
//If the command is slash type
const { Permissions } = require("discord.js")
interaction.guild.channels.create({
name: "new-channel",
type: 'GUILD_TEXT',
permissionOverwrites: [
{
id: interaction.guild.id,
accept: [Permissions.FLAGS.VIEW_CHANNEL],
},
],
});
//If the command is message type
const { Permissions } = require("discord.js")
message.guild.channels.create({
name: "new-channel",
type: 'GUILD_TEXT',
permissionOverwrites: [
{
id: message.guild.id,
accept: [Permissions.FLAGS.VIEW_CHANNEL],
},
],
});
I've seen some bots that have space in the name of their slash commands, ex: /admin ban
But when I try to implement it, I get an error saying that the name of the slash command does not match a validation regex.
My code:
guild.commands.create({
name: 'foo bar',
description: 'random description here'
});
Error:
DiscordAPIError: Invalid Form Body
name: String value did not match validation regex.
These are called subcommands. They are a good way to sort commands. For example, instead of using setsomething and deletesomething commands, you could use something delete and something set.
You can do this with the options property, and setting the type to SUB_COMMAND
guild.commands.create({
name: "foo",
description: "random description here",
options: [
{
type: "SUB_COMMAND",
name: "bar",
description: "some description"
}
]
})
You can get this in the interactionCreate event through .getSubcommand()
const subcommand = interaction.options.getSubcommand() // "bar"
I am trying to generate a ReadMe file using NodeJS and at this moment I am able to create the file but it is only returning [object Object]. I am not able to get the information from the questions I am answering in terminal. Also, I have second file linked to the index.js which should generate the template for the final ReadMe. At the moment I am not sure how to add it to the function to create the template.
const fs = require("fs");
const axios = require("axios");
const inquirer = require("inquirer");
const markdown = require("./utils/generateMarkdown");
const questions = [
{
message: "What is the name of the project?",
name: "title"
},
{
message: "Please provide a table on content",
name: "table of content"
},
{
message: "What is the name of the user?",
name: "userName"
},
{
message: "Please provide a description of the project",
name: "description"
},
{
message: "What is the installation process?",
name: "installation"
},
{
message: "How will this project be used?",
name: "usage"
},
{
message: "What licenses are required with this project?",
name: "licenses"
},
{
message: "Who were the contributors to this project?",
name: "contribution"
},
{
message: "What is the test process for this project?",
name: "test"
},
{
message: "What is the user github email address?",
name: "GitHub user email"
},
{
message: "Please provide a profile picture",
name: "GitHub profile picture"
}
]
function init () {
inquirer.prompt(questions)
.then((inquirerResponse, data) => {
console.log("Making ReadMe");
fs.writeFileSync("ReadMe.md", inquirerResponse, data);
})
.catch((err) => {
console.log(err);
})
}
init();
const userName = questions.userName
axios.get(`https://api.github.com/users/${userName}`)
.then(questions => {
console.log(questions.data);
});
Here's the code for the second file.
function generateMarkdown(response) {
return `
# ${response.title}
# Table of Content
-[description](#description)
-[installation](#installation)
-[usage](#usage)
-[licenses](#licenses)
-[contribution](#contribution)
-[test](#test)
-[username](#username)
-[profile](#profile)
${response.username}
##username:
${response.description}
##description:
${response.installation}
##installation:
${response.usage}
##usage:
${response.licenses}
##licenses:
${response.contribution}
##contribution:
${response.test}
##test:
${response.email}
##email:
${response.profile}
##profile:
`;
}
module.exports = generateMarkdown;
I am new to Meteor js and I am trying to create a form following the official guide http://guide.meteor.com/methods.html#method-form. It suggests to use mdg:validated-method package and aldeed:simple-schema for validation which are based on mdg:validation-error to return validation error messages to the client. The guide suggests this code then to handle validation
Invoices.methods.insert.call(data, (err, res) => {
if (err) {
if (err.error === 'validation-error') {
// Initialize error object
const errors = {
email: [],
description: [],
amount: []
};
// Go through validation errors returned from Method
err.details.forEach((fieldError) => {
// XXX i18n
errors[fieldError.name].push(fieldError.type);
});
// Update ReactiveDict, errors will show up in the UI
instance.errors.set(errors);
}
}
});
but the problem is that only fieldError.type, fieldError.name and first human readable message from simple-schema are available in err.error. I use translated messages and field labels in simple-schema to get nice understandable validation error messages. So getting just object property name with "required" is unacceptable, especially in the case when message includes min/max constraints for example. I could not find any way to get simple-schema's validation context to retrieve the full list of human readable errors.
So my question is can I get full error messages on the client and how?
Or maybe there are better ways to achieve what I am trying to do?
Thanks in advance
Hi! Recently I have encountered with the same problem.
So I just create pull request with some code enhancement to solve this issue. Now when you submit form and call validated-method from client side like following:
yourMethodName.call(data, (err) => {
if (err.error === 'validation-error') {
console.dir(err, 'error ')
}
});
You will see error object in the console:
{
"errorType": "ClientError",
"name": "ClientError",
"details": [
{
"name": "firstName",
"type": "required",
"message": "First name is required"
},
{
"name": "lastName",
"type": "required",
"message": "Last name is required"
},
{
"name": "phone",
"type": "required",
"message": "Phone is required"
},
{
"name": "email",
"type": "required",
"message": "Email is required"
}
],
"error": "validation-error"
}
So I just copy that from my console output.
In my case, the method is as follows:
export const yourMethodName = new ValidatedMethod({
name: 'my.awesome.method',
validate: new SimpleSchema({
firstName: { type: String },
lastName: { type: String },
phone: { type: Number },
email: { type: String, regEx: SimpleSchema.RegEx.Email }
}).validator({ clean: true }),
run(doc) {
YourCollection.insert(doc);
}
});
If my pull request will be accepted, you can easy use node-simple-schema (it is the next version of meteor-simple-schema).
If it won't you can use my fork.
Hope this helps!
EDIT: Now this feature available in official node-simple-schema package.