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"
Related
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],
},
],
});
//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!
Im coding a bot in Discord.js (Node) and I'm trying to send an embed with the server info, I've got all the code but it keeps causing a Bad Request and I've tried everything I know here's the code:
var FieldsData = [{ name: "Channels", value: msg.guild.channels.size }, { name: "Emojis", value: msg.guild.emojis.size }, { name: "Members", value: msg.guild.members.size }, { name: "Owner", value: msg.guild.owner }, { name: "Roles", value: msg.guild.roles.size }, { name: "Region", value: msg.guild.region }, { name: "Id", value: msg.guild.id }, { name: "Icon", value: msg.guild.iconURL }, { name: "Created At", value: msg.guild.createdAt }];
msg.channel.send('', {
embed: {
color: 37119,
title: "Server info for " + msg.guild.name,
fields: FieldsData
}
});
I've tried the message with just one field and it works,
I've tried it will each field by themselves and it works
but when I put them all together they make a Bad Request,
I've checked every line, every character and I'm just
stumped at what could possibly be causing this,
the max fields is 25 and I don't have that many,
all the variables are valid, none produce 'Null' or 'Undefined',
I've tried different setups of the code layout,
I've tried adding/removing parts, editing parts, replacing bits
here and there but to no avail I cant get it to work at all.
I've been trying to figure this out for 2 hours, I've searched online, docs, etc
Please Note: I'm not that advanced with javascript so if i've made a big mistake then don't be surprised.
"msg" is the object of the message, Example:
Bot.on('message', function (msg) { /*Stuff*/ });
I hope I've explained this enough, I'm using the LATEST version of Discord.js at the time of posting this and I'm not using ANY other extensions, packages, etc
SHORT ANSWER:
Now, don't just ignore this post after I say this (actually read my reasons, the whole thing), but please just use a Rich Embed
LONG ANSWER:
First of all, I strongly suggest using Rich Embeds, as it is easier to play with and edit. Anyways, here:
The first suggestion comes from your message event. In ES6, we now have arrow functions which look like this (arg1, arg2) => {doSomething();}, and using this new feature, your message event handler should look more like this:
client.on('message', msg => {
//Do my thing with that msg object
});
Now back to the point.
Objects are weird k? I believe that this: "Server info for " + msg.guild.name is not allowed. I don't know why, but when I tried to use a variable to display my bot's version, it gave me an error too. So if you want to fix that you have two options:
Recommended: Use Rich Embeds
Not Recommended: Use `${myVar}` instead (Not Tested)
Don't overcomplicate. What is this: ('', You can just do msg.channel.send({embed:{}});
You don't just use variables for the sake of it. What is the point of using FieldsData? It is only used once, and why can't you just do:
msg.channel.send({
embed: {
color: 37119,
title: "Server info for " + msg.guild.name,
fields: [{name: "Channels", value: msg.guild.channels.size}, { name: "Emojis", value: msg.guild.emojis.size }, { name: "Members", value: msg.guild.members.size }, { name: "Owner", value: msg.guild.owner }, { name: "Roles", value: msg.guild.roles.size }, { name: "Region", value: msg.guild.region }, { name: "Id", value: msg.guild.id }, { name: "Icon", value: msg.guild.iconURL }, { name: "Created At", value: msg.guild.createdAt }]
}
});
VERY IMPORTANT NOTE:
Now, you don't give any valid reason why you don't want to use Rich Embeds, because a rich embed is also an object. ;-; So just use a rich embed.
i have scripts that require the use of objects, and they are pre made
I wonder how you get access to your embed if its not stored.... Very interesting.
can you please tell me how to show different message on required and invalid ?In other word .make a form from json using plugin .In that there are some required parameter .and some I need to validate example "Email".When user press "submit" button if user did not fill the field it show "this field is required" .and if user fill the value but not same patten than it say "invalid value".can we show different message as different situation .
i used this plugin
https://github.com/Textalk/angular-schema-form/blob/master/docs/index.md#validation-messages
and I make this plunker
http://plnkr.co/edit/ZNJO3x3IqajjdMNStJMF?p=preview
angular.module('test',['schemaForm']).controller('FormController', function($scope,$http){
$scope.schema = {
type: "object",
properties: {
name: { type: "string", minLength: 2, title: "Name", description: "Name or alias" ,required:true,"default": "dddd"},
"student": { type: "string", title: "studentname", description: "Name or student" ,required:false},
"email": {
"title": "Email",
"type": "string",
"pattern":"\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*",
"description": "Email will be used for evil.",
required:true
},
title: {
type: "string",
required:true,
enum: ['dr','jr','sir','mrs','mr','NaN','dj'],
}
}
};
$scope.form = [
"*",
{
type: "submit",
title: "Save"
}
];
As you may read from the official angular-schema-form documentation
Per default all error messages comes from the schema validator tv4, this might or might not work for you. If you supply a validationMessage property in the form definition, and if its value is a string that will be used instead on any validation error.
If you need more fine grained control you can supply an object instead with keys matching the error codes of tv4. See tv4.errorCodes
Ex.
{
key: "address.street",
validationMessage: {
tv4.errorCodes.STRING_LENGTH_SHORT: "Address is too short, man.",
"default": "Just write a proper address, will you?" //Special catch all error message
}
}
You can also set a global validationMessage in formDefaults see Global Options.
So for more error messages, visit this link
Here is a great blog article that should answer your question: http://www.thebhwgroup.com/blog/2014/08/designing-html-forms-angularjs-part-1/
In particular, check out part 3 "Validation Messages and Styling".
From the article,
<span class="validation-message" ng-show="contactForm.firstName.$error.maxlength">Max length 20</span>
Where the ng-form is named contactForm and the element in question is named firstName. This puts the form on the scope and you can then traverse that to get the errors, and show an error message specifically for each error.
I'm building my first full-fledged angular app, and ran into an interesting quirk. I have a model whose data structure is something like this:
{
id: "12345",
host: {
name: "someHostServer",
ip-addresses: [
"1.2.3.4",
"10.11.12.13"
]
}
}
I am rendering a page where this structure is assigned to 'data' in the context, like approximately so:
ID: {{data.id}}
Host: {{data.host.name}}
IP Addresses:
<span ng-repeat="address in data.host.ip-addresses">
{{address}}<br />
</span>
ID will show up, host name will show up, but addresses? Nothin'. Is this because of the hyphen in ip-addresses? If so, is there a simple way to do a data transform? I'm getting this data from a simple $resource factory.
If you use . (dot) to get object property, it can't have -(hyphen) in property name.
So you must use ['property-name'] to access it.
<span ng-repeat="address in data.host['ip-addresses']">
{{address}}<br />
</span>
It's not that it doesn't accept properties with hyphens, it's that it is not valid json which will error out in javascript regardless of angular.
If your data was instead this:
{ id: "12345", host: { name: "someHostServer, "ip-addresses": [ "1.2.3.4", "10.11.12.13" ] } }
It would be ok, and you can try that out in chrome dev by doing this:
console.log({ "name": "someHostServer", "ip-addresses": [ "1.2.3.4", "10.11.12.13" ] });
Doing this:
console.log({ id: "12345", host: { name: "someHostServer, ip-addresses: [ "1.2.3.4", "10.11.12.13" ] } });
Results in an error.
Once you've made that change it looks like your markup should be
IP Addresses: {{data.host['ip-address']}}