1

I am currently coding a discord bot in discord.net. The command that I'm having trouble with is one that can display information about a user. If no parameter is given I already have it set up to display info about the current user.

    [Command("userinfo")]
    public async Task userinfo(IUser user = ???)

How would I pass a user here? I am using discord.net v1.0.2.

Tanner H.
  • 304
  • 1
  • 13
  • Possible duplicate of [How can you use optional parameters in C#?](https://stackoverflow.com/questions/199761/how-can-you-use-optional-parameters-in-c) – Unknown Jan 22 '18 at 00:05

1 Answers1

2

you simply have to set a default value for user, I recommend to use SocketUser instead of IUser.

Here is a code example:

    [Command("userinfo")]
    public async Task UserInfo(SocketUser user = null)
    {
        if (user == null)
        {
            user = Context.User;
        }
        ...
    }
JanMer
  • 1,198
  • 2
  • 17
  • 27
  • What is the difference between `IUser` and `SocketUser`? – Tanner H. Jan 31 '18 at 23:42
  • 1
    IUser is a Interface, SocketUser not ;) basicially u can do "more" with SocketUser because you can use the methods on SocketUser :) it works good for me – JanMer Feb 02 '18 at 09:43