Random quote command remodel


Random quote command remodel



I'm fairly new to JS, I found this piece of code for a Discord bot, and I was wondering how I could make it so when someone typed !quote, the response doesn't tag the user, and require additional text to be typed along with the command from the user. Thanks


if (command == "quote") {
if (args[1] != null) message.reply(quote[Math.floor(Math.random() * quote.length).toString(16)]); // if args[1], post random answer
else message.channel.send("!quote <your text here>");
}





Sorry, but the code you posted doesn't seem to have anything to do with your question. What user are you talking about? What command?
– Mark Meyer
Jul 1 at 6:52





I guess reply replies to the user, and channel.send sends a message to the channel?! I'm fairly new to JS ... Then first learn it before asking questions about it.
– Jonas W.
Jul 1 at 6:58



reply


channel.send


I'm fairly new to JS




1 Answer
1



Message.reply() sends a message in the same channel with a mention tag. If you don't want the mention tag, you have to send a message in the same channel, and you can do that with message.channel.send()


Message.reply()


message.channel.send()



Your code should look like this:


if (command == "quote") {
if (args[1] != null) message.channel.send(quote[Math.floor(Math.random() * quote.length).toString(16)]); // if args[1], post random answer
else message.channel.send("!quote <your text here>");
}



If you don't want to check for any additional text, you can just get rid of the if/else check, and only leave the message.channel.send():


message.channel.send()


if (command == "quote") message.channel.send(quote[Math.floor(Math.random() * quote.length).toString(16)]);





Thank you! is there anyway that when you type the command, you don't have to add any additional text? eg currently you have to do '!quote some-text-here' Sorry for being a nuisance
– Sassafras
Jul 1 at 11:39





Sure, no problem! I edited the answer
– Federico Grandi
Jul 1 at 11:58






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask

NSwag: Generate C# Client from multiple Versions of an API