'DM user by ID c#

I want to DM a user by ID using c#, Here's what I've tried

        var u = "user-id";
        string msg = "your message";
        await UserExtensions.SendMessageAsync(u, msg);

It returns with:

cannot convert from 'string' to 'Discord.IUser'

I've searched and I couldn't find away to turn a string to Discord.IUser.



Solution 1:[1]

You need to get the user as IUser, to get the user as IUser you can use _client.GetUserAsync('UserID'):

ulong u = 0; // Insert the user ID here
string msg = "your message";

// Get the user with the ID from your DiscordSocketClient
var user = _client.GetUserAsync(u).Result;

await UserExtensions.SendMessageAsync(user, msg);

Solution 2:[2]

var user = Context.Guild.GetUser(Context.Message.Author.Id);
await user.SendMessageAsync("This is my message!");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BobSty
Solution 2 user18494041