suicvne / discordsharp Goto Github PK
View Code? Open in Web Editor NEWA .Net API for Discord written in C#
License: MIT License
A .Net API for Discord written in C#
License: MIT License
I'm using the current NuGet version at the time of writing this (0.6.2.0), and it seems that the websocket repeatedly closes itself every minute or two. No clue why it's doing this.
Hey, it would be awesome, if you could make an event that fires when the serverlist is fully received. I have some functions in the connected event, that needs the fully serverlist.
Best regards
The bot for our server is used to parse a lot of data and sometimes it needs to send 10 ~ 15 messages to a single person.
is there a way to have it wait for however long the discord server requires me to wait and then resend the message?
I have tried using a try with catch (RateLimitException ex) but it seems to be completely ignored.
Help Plz, When I Put The Bot.SetGame Don't Display The Game And Say: The Name "bot or client" does not exist in the current context. Help me plz
I have been using DiscordSharp 0.6.2-rc1 from NuGet and was talking to another bot dev who had a GitHub release (version 0.6.0.50-dev). His libraries contained a DiscordRole class, while the NuGet version doesn't. I'm not sure if it was removed in the newer NuGet and GitHub version or was not included in one.
Hello,
I've been using this API for my bot and it's working like a charm.
Though, I wonder if there's a way to attach/send a file to a certain user/member from a channel, unlike client.AttachFile(DiscordChannel channel, string message, string pathToFile)
which sends the attachment to the whole channel.
Thank you,
Hey everyone i would like understand how i can set a status on my account.
I try use this command await discord.UpdateStatusAsync(new DiscordActivity("!help", DSharpPlus.Entities.ActivityType.Playing), UserStatus.DoNotDisturb);
, but he return this:
System.NullReferenceException: 'Object reference not set to an instance of an object.'.
Is possible change status of account?
Hi there I'm getting Out of Memory errors when using the NuGet package.
I think I've tracked it down to DiscordSharp.Logger eating all the memory could you maybe give some insight to this.
I ran into an interesting issue when my group needed to clear out the default discord text channel. Since it's the default one, it couldn't just be deleted and remade. We actually had to delete however many months worth of messages.
Unfortunately, the default behavior of DicordClient.DeleteAllMessagesInChannel() only deletes messages in the client's MessageLog which only seemed to go as far back as when the bot logged in.
I changed the method to
public int DeleteAllMessagesInChannel(DiscordChannel channel)
{
int count = 0;
// Grab the most recent 100 messages.
var messages = this.GetMessageHistory(channel, 100, null, null);
while (messages != null && messages.Count > 0)
{
count += messages.Count;
foreach (var message in messages)
{
// Probably a redundant check but might be good to keep.
if (message.channel == channel)
{
this.SendDeleteRequest(message);
}
}
// Grab the most recent 100 messages.
messages = this.GetMessageHistory(channel, 100, null, null);
}
return count;
}
I didn't want to make a pull request since I'm not sure if you even intend to support this functionality. But it might be good to at least offer a new method that can truly prune an entire channel.
The only question is how Discord's API will react to that number of requests. If the API does have a flood limit, you could add a sleep to the loop or something. Otherwise, it might be impetus for the Discord devs to add a "Delete all messages in this channel" function to the app or API.
I'm new to this so please bare with me.
I just tried to make my first bot. I used the code given by https://github.com/NaamloosDT/DiscordSharp_Starter.
I'm getting two issues:
Code snippet:
client.Connected += (sender, e) =>
{
Console.WriteLine($"Connected! User: " + e.user.Username);
Console.WriteLine("Updating Status");
client.UpdateCurrentGame("Sleeping");
};
Console Output:
Updating Status
4/14/2016 2:54:01 AM|Error|WebSocket.Send|The WebSocket connection has already been closed.
Is there a possibility of Two-Factor-Authentication?
A lot of the newer Discord features like friends don't seem to have a hook in this framework. Is this project dead?
Hi, every time I call Connect method, I got 401 - Unauthorized response code. Any idea why?
Hey, you are missing a field assignment for the user field when creating DiscordPresenceUpdateEventArgs in file DiscordClient.cs at line 533+.
DiscordPresenceUpdateEventArgs dpuea = new DiscordPresenceUpdateEventArgs();
dpuea.RawJson = message;
var pserver = ServersList.Find(x => x.members.Find(y => y.user.id == message["d"]["id"].ToString()) != null);
if (pserver != null)
{
var user = pserver.members.Find(x => x.user.id == message["d"]["id"].ToString());
You are missing
dpuea.user = user;
public DiscordClient(string tokenOverride = null, bool isBotAccount = false)
{
token = tokenOverride;
**isBotAccount = IsBotAccount;**
// more code
}
Seems to me as a typo as it should be IsBotAccount = isBotAccount
, since this way you are assigning a default (false) value to the supplied parameter variable. This way the bot never adds the appropriate values to auth headers.
Hey there.
Just a side note, you may not want to display bad practices like "while (true);" in example applications. Consider reworking that example to use a waithandle. I was a bit terrified when I noticed the testapp was consuming 100% of one core, but it wasn't difficult to pinpoint the culprit after checking out the code.
Aside of that, this is some fine work, this API is very easy to work with. My discord bot based on your API hovers around 7mb memory usage and is almost always at 0% cpu usage. π
So nicknames per server was recently added, i would like to request this to be added to DiscordSharp π
Thanks in advance and keep up the great work!
hasPermission(DiscordSpecialPermissions.Administrator)???
Hey, could you extend the API to support moving users over channels?
Sth. like:
'server.MoveMember(member, channel)'
I tried to make it myself, but my skills in JSON APIS's is ehm, so ye...
OR - If there is feature like this, could you say something about it?
Thanks
simply running DiscordServer.CreateChannel("foo", true) will return an object reference not set to an instance of an object exception.
Please help me, I searched for a long time but couldn't find anything. I want to send the message without answering a message.
I know this is dead but discord.net isn't compatible with something of mine and this works really well as a temp work around.. But yeah how do i login with a bot token?
I'm new to github, hope this is the right section, anyway can I make my DiscordClient log in with a bot account? How?
Hey, not sure if this is the right place to post this but this was the last thing I could think of. Basically I'm unable to update to the latest version with the following error message:
Install-Package DiscordSharp -Pre
Attempting to gather dependencies information for package 'DiscordSharp.0.5.3-alpha' with respect to project 'DiscordBot', targeting '.NETFramework,Version=v4.5.2'
Attempting to resolve dependencies for package 'DiscordSharp.0.5.3-alpha' with DependencyBehavior 'Lowest'
Resolving actions to install package 'DiscordSharp.0.5.3-alpha'
Resolved actions to install package 'DiscordSharp.0.5.3-alpha'
Removed package 'DiscordSharp.0.5.1-alpha' from 'packages.config'
Successfully uninstalled 'DiscordSharp.0.5.1-alpha' from DiscordBot
Adding package 'DiscordSharp.0.5.3-alpha' to folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Added package 'DiscordSharp.0.5.3-alpha' to folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Install failed. Rolling back...
Package 'DiscordSharp.0.5.3-alpha : NAudio [1.7.3, ), Newtonsoft.Json [8.0.2, ), WebSocket4Net [0.14.1, ), WebSocketSharp [1.0.3-rc9, )' does not exist in project 'DiscordBot'
Package 'DiscordSharp.0.5.1-alpha' already exists in folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Added package 'DiscordSharp.0.5.1-alpha' to 'packages.config'
Removing package 'DiscordSharp.0.5.3-alpha : NAudio [1.7.3, ), Newtonsoft.Json [8.0.2, ), WebSocket4Net [0.14.1, ), WebSocketSharp [1.0.3-rc9, )' from folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Removed package 'DiscordSharp.0.5.3-alpha : NAudio [1.7.3, ), Newtonsoft.Json [8.0.2, ), WebSocket4Net [0.14.1, ), WebSocketSharp [1.0.3-rc9, )' from folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Install-Package : Failed to add reference to 'opus'.
At line:1 char:1
+ Install-Package DiscordSharp -Pre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
package 'DiscordSharp.0.5.3-alpha' to folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Install failed. Rolling back...
Package 'DiscordSharp.0.5.3-alpha : NAudio [1.7.3, ), Newtonsoft.Json [8.0.2, ), WebSocket4Net [0.14.1, ), WebSocketSharp [1.0.3-rc9, )' does not exist in project 'DiscordBot'
Package 'DiscordSharp.0.5.1-alpha' already exists in folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Added package 'DiscordSharp.0.5.1-alpha' to 'packages.config'
Removing package 'DiscordSharp.0.5.3-alpha : NAudio [1.7.3, ), Newtonsoft.Json [8.0.2, ), WebSocket4Net [0.14.1, ), WebSocketSharp [1.0.3-rc9, )' from folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Removed package 'DiscordSharp.0.5.3-alpha : NAudio [1.7.3, ), Newtonsoft.Json [8.0.2, ), WebSocket4Net [0.14.1, ), WebSocketSharp [1.0.3-rc9, )' from folder 'A:\docs\PROGRAMMING\C#\Projects\DiscordBot\packages'
Install-Package : Failed to add reference to 'opus'.
At line:1 char:1
+ Install-Package DiscordSharp -Pre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
I'm using VS2015 and both the IDE and nuget are updated to the latest version. This issue occurs only when I'm trying to install this particular package (I thought at first that the dependencies might cause it but their install went fine on its own). Trying it out on a different computers produced the same error message.
I've tried clearing the nuget package cache, I've deleted all relevant packages manually, I've tried adding your package into a completely new project. Nothing worked.
Updating to the previous version works fine.
So my question basically is - could this be a package issue? Are you perhaps able/willing to test this out in your IDE?
Found a similar issue here and a package update solved the issue.
"4/6/2016 5:25:04 PM|Error|WebSocket.Send|The WebSocket connection has already been closed."
Been getting this error. Using the DiscordSharp provided here and the "Getting Started bot" from NaamloosDT. This is the error I get after I cleaned up the code a little and such. Had to import a new .dll of DiscordSharp because the default one with the getting started bot wasn't working correct.
Any help with this?
From Luke on Discord:
Hey man, Is the AcceptInvite function working? It seems to run fine but doesnt actually join the server.
Error 411 (Length Required)!!
411. That's an error.
POST requests require a Content-length header. That's all we know.
Must investigate.
The Connected
event doesn't write anything to the console after starting. I changed client.ClientPrivateInformation.email
and client.ClientPrivateInformation.password
to client.ClientPrivateInformation.Email
and client.ClientPrivateInformation.Password
. It used to work just fine, not sure what changed. I have version 0.6.0.7-rc1
according to NuGet.
During the login of my bot it all of a sudden has started giving the following error.
Console log:
[19:17:24][INFO] Attempting login..
[19:17:24][INFO] Logged in.
[19:17:28][ERROR] Socket Closed! Code: 4002. Reason: Error while decoding payload.. Clear: True.
[19:17:28][INFO] Waiting 6 seconds to reconnect..
[19:17:28][INFO] Connected! User: Bot
Websocket log file:
05-Apr-16 20:40:44|Fatal|WebSocket.processException|WebSocketSharp.WebSocketException: The 'Payload Data' of a frame cannot be read from the data source.
at WebSocketSharp.WebSocketFrame.read(Byte[] header, Stream stream, Boolean unmask)
at WebSocketSharp.WebSocketFrame.<>c__DisplayClass7.b__6(Byte[] header)
at WebSocketSharp.Ext.<>c__DisplayClass6.b__5(IAsyncResult ar)
Might any of you know what may be causing this?
Couple of questions. How can I make it respond to what was said in a voice chat room. Or do an event when someone joins and room and use the microphone in discord?
Or just not possible?
I'm having a hard time finding much documentation on this so I decided to just ask here. How can I have my bot see and download any images sent on my discord server?
Sorry if I am putting this in the wrong spot
Well anyway i need help streaming an MP3 file through the client I can't find
ANY documentation anywhere. Thank you!
"System.TypeLoadException was unhandled
Message: An unhandled exception of type 'System.TypeLoadException' occurred in mscorlib.dll
Additional information: Could not load type 'DiscordSharp.DiscordClient' from assembly 'DiscordSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."
I get this error whenever I compile. I could have overlooked something but I have no idea why this is happening. I am using version 0.6.2-rc1.
This might have to do with changes in events at discordsharp-v0.6.0.68-dev.
When I run the code:
Client.ConnectToVoiceChannel(args.Author.CurrentVoiceChannel);
It seems to always return an NPE on the CurrentVoiceChannel, although I'm the one sending the command to execute this and I am in a voice channel it still throws an NPE and I'm not sure why
Hey, love your library here. I'm trying to run this on mono and when i call .Connect() it seems to halt up there. Have you had any issues relating to that?
Thanks!
More of a suggestion than an issue since this event doesn't seem to be documented nor listed anywhere.
According to Discord.Net
's documentation. It lists,
Event Name | EventArgs | Description |
---|---|---|
UserIsSpeaking Updated | UserEventArgs | Called when a userβs voice state changes. (Speaking\Not Speaking) |
But has no example using it. Does DiscordSharp
have such an event?
I'm writing an application that alerts the user when somebody in a voice channel starts speaking.
Not sure if it's my app, but all of my event handlers work perfectly fine - except for this one:
DiscordClient client = new DiscordClient(token, true);
client.Connected += (sender, e) => {
// code in here never runs
};
I have tried replacing it with other things, other forms of things, I've tried debugging it, but it never fires.
(Reported by Kazurik
on Discord)
The following example: https://gist.github.com/davidneumann/6e5d49dd3cd82e0b0603
Will fail and give the following error:
The request was aborted: The request was canceled.
Could be an HttpWebRequest
bug.
How would i get the bot to remove a member/user from a role... i know how to add but i cant remove... i will set all the roles except for the one being removed for now...
Here is my snippet code
if (voiceChannels.Count > 0)
{
client.ConnectToVoiceChannel(voiceChannels[0]);
Thread.Sleep(1000);
DiscordVoiceClient vc = client.GetVoiceClient();
if (vc != null)
{
WriteLine("WAV sent");
vc.SendWav(@"C:\Users\Adrien\gaben.wav");
}
else
{
WriteLine("WAV not sent");
client.DisconnectFromVoice();
}
}
It throws a NullReferenceException when trying to do DiscordVoiceClient vc = GetVoiceClient()
, more specifically, I have a tiny stacktrace that the exception is thrown by line 1337 from DiscordClient.cs
Because of this, I cannot use in any way the voice client.
Tried making a simple echoing to echo back my voice in discord. Basically is looks like it does below.
and it doesn't ever write to line or echo anything back to me even tho he is already in the voice channel. Any help would be great!
client.ConnectToVoiceChannel(client.GetChannelByName("Other"));
client.AudioPacketReceived += (sender, e) =>
{
Console.WriteLine("Audio Packet Recieved");
DiscordAudioPacket audio = new DiscordAudioPacket(e.OpusAudio);
client.EchoPacket(audio);
};
Can it be done in the current iteration of the API?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.