ThePebbleStealer
ThePebbleStealer

Reputation: 15

C# + Discord.NET - Command with string?

So I want to create a command, where the user types in the command with something else and a string is being defined by that. That string is later used to redirect the user to a website.

Meaning:

//The string is defined here by user (string = what user typed in after "command") (how?)
commands.CreateCommand("command", string add_link)

            .Do(async (e) =>
            {
//String is added to website.
                await e.Channel.SendMessage("www.website.com/" + add_link);
            });

Is that even possible?

Upvotes: 0

Views: 1858

Answers (1)

0xFF
0xFF

Reputation: 838

It's pretty simple, you just need to add a call to .Parameter() to define it then retrieve it with GetArgs(). See this example:

 cmd.CreateCommand("linkit")                
 .Parameter("url", ParameterType.Unparsed)
 .Do(async e =>
 {
     string msg = e.GetArg("url");                        
     await e.Channel.SendMessage("the text is: "+msg);
 });

This would be used like this (assuming your bot's key is '!'):

[fhl] !linkit foobar
[bot] the text is: foobar

Example adapted from this Sample Bot: https://github.com/RogueException/DiscordBot

Upvotes: 1

Related Questions