Input text has too few parameters - C# Discord bot - c#

I'm pretty new to all of this, so excuse the fact that this is probably a massive facepalm moment to most people here. I'm trying to get my Discord bot to play audio. It'll join the channel but whenever I use the play command it says "the input text has too few parameters" in the discord chat. As I said I'm new to this so don't know where to start. Here's what I have for the play command;
[Command("play", RunMode = RunMode.Async)]
public async Task PlayCmd([Remainder] string song)
{
await _service.SendAudioAsync(Context.Guild, Context.Channel, song);
}
}
That's just the basic play command I have with nothing extra added just yet. Also, how would I get it to play a specific file? I'm unsure of where or how to add the file path to the command.

Based on the code you provided I assume that you need to give the song-name as the parameter in your command. The function PlayCmd does take a string as a parameter.
Try to use your commad in discord like this syntax:
command parameter
. For example: play Tetris

Related

How do I add a pause between voice prompt choices in Twilio Voice using C#?

I'd like to be able to accomplish the following by editing the code below using Twilio Voice (TwiML) in C# (in a C#/Core Web Application):
Add a brief pause of say 300ms between voice prompt choices
Add emphasis to certain words in the prompt (e.g. friend, internet,
other, etc)
Allow user to say "friend" and interrupt the readout, which in turn invokes the action uri
Twilio has an example of how to mark up a "Say" object at https://www.twilio.com/docs/voice/twiml/say/text-speech but it doesn't account for how to merge that with a gather object. It seems that merging the Say is the recipe so that the listener is able to interrupt the choices at any point by saying "friend", skipping the rest of the readout of choices, and to invoke the action Uri.
I have been able to construct a gather object and append separate Say methods as shown in my example code below. Note that the code below compiles and works, but I don't know how to pause the text-to-speech readout between options to give person a 300ms to blurt out "friend". Also, it seems to wait the entire three second default when you say "friend" instead of recognizing that as the user input and invoking the action uri more quickly. Using the keypad digits works as desired, but I want to get the speech-to-text capability to work more efficiently.
This is my first question posted, so let me know if I need to include any other information.
Here are my relevant "using" statements:
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Twilio.AspNet.Common;
using Twilio.AspNet.Core;
using Twilio.TwiML;
using Twilio.TwiML.Voice;
Here is the function in the class I am working on:
private static void RenderReferralSource(VoiceResponse response)
{
string hintchoices = "friend, internet, other,";
List<Gather.InputEnum> bothDtmfAndSpeech =
new List<Gather.InputEnum>(2) { Gather.InputEnum.Dtmf, Gather.InputEnum.Speech };
var mygather = new Gather(input: bothDtmfAndSpeech,
action: new Uri("/voice/GatherReferralSource", UriKind.Relative),
speechModel: Gather.SpeechModelEnum.NumbersAndCommands,
enhanced: true,
hints: hintchoices,
bargeIn: true,
speechTimeout: "3",
numDigits: 1);
mygather.Say("How did you find us, or who referred you to our practice?", voice: "Polly.Joanna-Neural");
string digmenu = "I will read a list of five choices. Press the number or say the word ";
digmenu += "as soon as you hear the correct choice of who referred you, ";
mygather.Say(digmenu);
mygather.Say("Press 1, or say Friend, if a friend, family member, or other customer of ours referred you,");
mygather.Say("Press 2, or say Internet, if you found us on Google or through an internet search,");
mygather.Say("Press 3, or say Martian, if someone from Mars referred you,");
mygather.Say("Press 4, or say Chuck Norris, if he ordered you to visit us,");
mygather.Say("Press 5, or say Other, for any other way,");
// Ask user and gather response
response.Append(mygather);
// If no choice, redirect
response.Redirect(new Uri("/voice", UriKind.Relative));
}

Unity Android: NoClassDefFoundError: Can't create Notifications

Edit
I found out, that the requirements for showing a notification consist of setting a content-title, a context-text and a small icon. The last of which I do not do. Unfortunately, I don't know, how to provide a small icon especially in unity.
Original Question
I'm currently trying to show a notification from a unity-instance via android. I want to show the notification, when the user enters a specific gps-area. Thus, the script should run, when the app is paused. That's why I want to use the android-functionality.
With this code, I currently try to show the notification manually:
public void createNotification(){
NotificationManagerCompat nManager = NotificationManagerCompat.from(curContext);
NotificationCompat.Builder builder = new NotificationCompat.Builder(curContext, CHANNEL_ID)
.setContentTitle("Stuff")
.setContentText("MoreStuff")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
nManager.notify(1551, builder.build());
}
The context is stored in a static variable and is set, when calling the method.
The function is called in C# with:
PluginInstance.Call("createNotification");
The PluginInstance works, the function can be called, but I get the error:
AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/NotificationManagerCompat
I found the solution for my problem: I used the Unity Android Jar-Resolver in which I provided the *Dependencies.xml (Where the * presents the Name of my project). In the *Dependenices.xml I specified: <androidPackage spec="androidx.appcompat:appcompat:1.1.0"> and run through the steps, provided in the Tutorial of the Resolver.
Afterwards, multiple dependencies appeared in my /Assets/Plugin/Android-Folder, which were successfully transferred to the app, when building it.

BitcoinLib usage in c#

So this is maybe dumb but I am using BitcoinLib for c# and I am trying to get to work this line:
IBitcoinService BitcoinService = new BitcoinService("https://localhost:5051/", "aaa" ,"aaa","vvvv", 5);
What I dont know: What to input there. I tried watching videos or documentation but theres anywhere said what website/password/acc and all to input. Then When I know what to input, how can I mine and then send bitcoins to my wallet? I know this is stupid but I really dont understand how to programate it...
What I tried: I have tried reading a documentation, I have tried watching some videos, downloading demo of app and nothing helped me. Either I am dumb or it's complicated.
Btw: I know how mining and bitcoin works (basics)
Configure your Bitcoin Core wallet properly in bitcoin.conf:
rpcuser = MyRpcUsername
rpcpassword = MyRpcPassword
server=1
txindex=1
Then you can just initiate the BitcoinService like that:
IBitcoinService BitcoinService = new BitcoinService();
and it will work; you don't need to explicitly define them inside the code. If you need to change these parameters in runtime you can do so by calling:
(IBitcoinService).Parameters

Discord.NET Adding Reactions to a SocketMessage

I am using Discord.NET version 1.0.2 to clear things up
I have a MessageReceived Task in my Discord Bot application:
private async Task MessageReceived(SocketMessage message)
This task, as can already be deducted, runs every time a message is received in Discord to this bot. I am trying to figure out how to add a reaction to a message that the bot has received, however. Under SocketMessage there are no methods to add reactions to the message received. I looked online and found that RestUserMessage contains the method AddReactionAsync(IEmote, RequestOptions). I then casted Socket Message to a RestUserMessage as so
var rMessage = (RestUserMessage) await message.Channel.GetMessageAsync(message.Id);
Running the AddReactionAsync method under my variable rMessage for RestUserMessage works, but the parameters are not taken correctly as I can perceive from my reading online and the documentation.
IEmote appears to be a string, but a string does not fulfill this parameter, saying that there is no conversion from a String to an IEmote. I tried casting this String to an IEmote but that did not work.
The RequestOptions variable seems to fulfill the parameter perfectly fine as a new RequestOptions().
My full code for this is:
private async Task MessageReceived(SocketMessage message)
{
var rMessage = (RestUserMessage) await message.Channel.GetMessageAsync(message.Id);
rMessage.AddReactionAsync(???, new RequestOptions());
}
How do I fulfill this IEmote parameter correctly and or how do I define an IEmote variable. Also, is defining a new RequestOptions() variable the correct thing to fulfill this parameter as well. Is this also the correct way to add reactions to a message through Discord.NET and if not what is?
The research I have done:
https://github.com/RogueException/Discord.Net/issues/490
https://discord.foxbot.me/docs/api/Discord.Rest.RestUserMessage.html
https://discord.foxbot.me/docs/api/Discord.IEmote.html
https://discord.foxbot.me/docs/api/Discord.RequestOptions.html
If you head over to Emojipedia, and grab the unicode version as shown below :
After that is copied, you have to create a new Emoji object, like so :
var YourEmoji = new Emoji("😀");
You can then add a reaction to the desired message, I'm going to use Context.Message :
Context.Message.AddReactionAsync(YourEmoji);
Unknown's solution works for regular emotes, but won't work for guild-specific emotes.
This is the solution I came up with:
SocketGuild guild = ((SocketGuildChannel) message.Channel).Guild;
IEmote emote = guild.Emotes.First(e => e.Name == "my-custom-emote");
message.AddReactionAsync(emote);
You already found the way to adding the emoji, but I'll follow up with an additional way of adding a guild emoji to a message. You'd need the raw string of the emoji in this case. Don't confuse it with Emoji, Emoji represents an Unicode emoji, but Emote is from Discord.Net and stands for a custom emoji. The AddReactionAsync method accepts both objects thanks to the IEmote interface.
Emote emote = Emote.Parse("<:craig_cat:603083214281506817>")
In this case, we're creating an Emote object with the emoji called craig_cat and the provided ID.
In order to get the raw string to parse, in your Discord client, simply send the emoji (:craig_cat:), but with a backslash (\) before it.
Note, in case of an animated emoji, it will look like the following:
Emote emote = Emote.Parse("<a:running:703588456198307900>")
There has to be an a before the punctuation mark to identify it as an animated emoji.
In both cases, you can add it to the message by these examples:
Context.Message.AddReactionAsync(emote); //Adds the reaction to the user's message that triggered the task (works only in a command)
Most of the other interfaces/objects also support this method, casting would help though.
You can also use this raw format at any time to include the emoji in a message.

Discord.NET 0.9.4 Audio does play with NAudio

I folllowed this documentation about the Discord.NET 0.9.4 API. Now i have this function called SendAudio, but i don't know how to call it correctly. I currently have this test code:
musicgroup.CreateCommand("play").Do((e) =>
{
Console.WriteLine("Hey, that's pretty good!");
SendAudio(AppDomain.CurrentDomain.BaseDirectory + "\\test.mp3");
});
It displays the "Hey, that's pretty good!" in the command line and the bot does show up in the Voice Chat, but i can't hear any sound. The bot has all permissions to talk. When i type !voice (the command to make the bot join Voice-Chat) I get this output in console:
[BOT] Unknown Opcode: 8
[BOT] Connected

Categories