c# - Creating a Discord-Bot command with "multiple" parameters -
i'm trying design command allow user call bot using specific command, , have bot read in entire string user passes in.
the problem here, discord bot takes in first word following command, , ignores rest.
commands.createcommand("sarcastify").parameter("input", parametertype.multiple).do(async (e) => { string userinput = e.getarg("input"); string output = sarcastify(userinput); await e.channel.sendmessage(output); }); if couldn't tell i'm making command allows user request "sarcastic" version of input text, aka 1 spongebob meme.
anyways, when command called, first word taken in
//in discord chat window $sarcastify program works //response is there way discord bot take in entire string parsing?
i'm not sure how discord.net api handles parameter name (beyond single parameters), know when discord reads in command parameters, stores them in array called 'args' can accessed , used normal array of strings.
so if ran
$sarcastify program works then within command function: e.args[0] = "this", e.args[1] = "program", e.args[2] = "works" e.t.c
so if want input 1 string, can use string.join() method on array, code this:
commands.createcommand("sarcastify") .parameter("input",parametertype.multiple) .do(async (e) => { string userinput = string.join(" ", e.args); string output = sarcastify(userinput); await e.channel.sendmessage(output); }); with code input:
$sarcastify program works would produce desired output : program works
:)
Comments
Post a Comment