Prefix in commandhandler - discord.js

When created in a command, this command is called every prefix. So suppose I have created a "help" command, then I can use everything as a prefix.
Examples:
!Help
?Help
.Help
-Help
How do I set that I have a fixed prefix.
(I use a command handler by the way)

I don't get what you mean. Do you want to use !, /, -, etc.. prefixes for your help command ? Or do you want a one prefix like !?
Based on your answer you want this:
Create a JSON file named config inside your projects
{
"prefix": "YOUR PREFIX HERE"
}
In your main file do
const { prefix } = require("./config.json");
bot.on('message', message => {
if (!message.content.startsWith(prefix)) return;
})

Related

Get Number from Slash Command and put it on a link

So, if a user says /GetProfile (EnterNumberHere)
The Number from that command should go at the end of a link
for example, i said /GetProfile 1 the number "1" should go at the end of this link
"http://cubestoria.ezyro.com/User/?id="
So, then the bot will respond with http://cubestoria.ezyro.com/User/?id=1
https://i.stack.imgur.com/dYCU0.png
I want to look like this but their is a option (like the diet in the photo) that you can put a number in.
Use ${variable} to put variable in string:
// ...
.addNumberOption(option => option.setName('diet').setDescription('...'))
const number = interaction.options.getNumber('diet')
interaction.reply(`http://cubestoria.ezyro.com/User/?id=${number}`)

How to make "this command cannot found" discord.js

I'm a bot developer and I own a music bot. I want to make this: how to make this command cannot found discord.js (I mean if someonee enter a command like m!pla then bot will say "U mean this? m!play")
You can use the npm package meant. It uses the Levenshtein Difference algorithm to find the most likely match given a string and an array of strings to compare it to.
const meant = require('meant');
const result = meant('foa', ['foo', 'bar', 'baz']) // => [ 'foo' ]
All you need is an array of your command names, and the command the user tried to execute.
const meant = require('meant');
const [result] = meant(commandName, commandNames);
// Did you mean ${result}?

Conditional statements for aliases

I am trying to add variation to different aliases, without having to rewrite the entire command:
#bot.command(aliases=['test'])
async def example(ctx)
if alias=='test':
#do something first
else:
#run command
Possible Solutions:
The error is the naming of the statement. I Have tried using command.aliases and aliases
Any help would be appreciated.
This is available as ctx.invoked_with
The command name that triggered this invocation. Useful for finding out which alias called the command.
ctx.message.content.split(' ')[0].strip(ctx.prefix)
Is a pretty good way to get the invoked command, so you could do something like
#bot.command(aliases=['test'])
async def example(ctx):
command_ran = ctx.message.content.split(' ')[0].strip(ctx.prefix)
if command_ran == 'test':
#do something first
else:
#run command

solr : how to add extra fields values not in the document

I know lucene, just started to learn how to use solr. In the simple example, the way to add document is to used the example ../update -jar post.jar to add document, the question is without writing my own add document in java, using the same way (... post.jar), is there a way to add additional fields not in the document? For example, say my schema include name, age, id fields, but the document has no 'id' field but I want the id and its value to be included, of course I know what id and value I want but how do I include it?
Thanks in advanced!
I don't believe you can mix the two. You can use post.jar to add documents using arguments passed in on the commandline, a file, stdin or a simple crawl from a web page but there is no way to combine them. In the source code for post.jar you can see it's a series else if statements so they are mutually exclusive.
-Ddata args, stdin, files, web
Use args to pass arguments along the command line (such as a command
to delete a document). Use files to pass a filename or regex pattern
indicating paths and filenames. Use stdin to use standard input. Use
web for a very simple web crawler (arguments for this would be the URL
to crawl).
https://cwiki.apache.org/confluence/display/solr/Simple+Post+Tool
/**
* After initialization, call execute to start the post job.
* This method delegates to the correct mode method.
*/
public void execute() {
final long startTime = System.currentTimeMillis();
if (DATA_MODE_FILES.equals(mode) && args.length > 0) {
doFilesMode();
} else if(DATA_MODE_ARGS.equals(mode) && args.length > 0) {
doArgsMode();
} else if(DATA_MODE_WEB.equals(mode) && args.length > 0) {
doWebMode();
} else if(DATA_MODE_STDIN.equals(mode)) {
doStdinMode();
} else {
usageShort();
return;
}
if (commit) commit();
if (optimize) optimize();
final long endTime = System.currentTimeMillis();
displayTiming(endTime - startTime);
}
http://svn.apache.org/repos/asf/lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
You could try to modify the code but I think a better bet would be to either pre-process your xml files to include the missing fields, or learn to use the API (either via Java or hitting it with Curl) to do this on your own.

CakePHP Router: how to pass the first parameter null?

My action is defined like this:
function actionName($par1 = null, $par2 = null)
I need a special route looking like: example.com/r/ABCD which should call
SomeController->actionName(null, "ABCD")
How is it to achieve with Cake's Router::connect() ?
You can try reversing the params like
function actionName( $par2 = null, $par1 = null)
1.- arg1 optional, arg2 not optional
I would change the order of the parameters, so the first parameter is truly optional.
2.- arg1 optional, arg2 not optional, without reordering
(not the best idea, but I assumed business rules required it)
Make a wrapper function.
SomeController {
wrapperFun(arg2) {
actualFunction(null, arg2)
}
actualFun(arg1, arg2) {
// do something
}
}
Now you can have:
SomeController/wrapperFun/ABC
SomeController/actualFun/arg1/ABC
And then with the magic of routing, you can redirect actualFun/ABC to wrapperFun/ABC. So the user will only see pretty URLs.
3.- arg1 optional, arg2 optional
So you have 4 possible options, right?
somecontroller/action/arg1/arg2
somecontroller/action/arg1
somecontroller/action/arg2
somecontroller/action
I believe this is your actual question:
How do I deal with functions that have multiple optional arguments?
In this cases what you need to use are associative arrays. That is actually how CakePHP does it in many parts. It looks like this:
$arr = {"arg2" => "some val"};
// calling the function with $arr
// some_action($arr);
some_action($argArr) {
$arg1 = isset($argArr["arg1"]) ? $argArr["arg1"] : null;
$arg2 = isset($argArr["arg2"]) ? $argArr["arg2"] : null;
}
Now, about the URLs, that is for you to decide. You must have a mechanism that will tell you what value is represented by each section of the URL. What comes to mind are two options:
First, use place holders (ugly):
some_controller/some_action/arg1/non/arg3/non/arg4
Or, use wrapper actions, similar to what is seen before in my answer (ugly too).
some_controller/action5/arg5
// then in the wrapper (action5) you have:
action5(arg) {
$arr = {"arg5" => arg};
some_action($arr);
}
As you can see this can get out of hand easily. I don't know what you are actually trying to do, but it seems that you are sending data by the wrong channel.
You might want to use a POST and use an array directly, instead of building your own, check out the request object.

Resources