Skip to main content

Class UserExtensions

An extension class for various Discord user objects.

Assembly: Discord.Net.Core.dll​
View Source​
Declaration
public static class UserExtensions

Methods​

SendMessageAsync(IUser, String, Boolean, Embed, RequestOptions, AllowedMentions, MessageComponent, Embed[])​

Sends a message via DM.

View Source​
Declaration
public static async Task<IUserMessage> SendMessageAsync(this IUser user, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent component = null, Embed[] embeds = null)
Returns​

System.Threading.Tasks.Task<Discord.IUserMessage>: A task that represents the asynchronous send operation. The task result contains the sent message.

Parameters​
TypeNameDescription
Discord.IUseruserThe user to send the DM to.
System.StringtextThe message to be sent.
System.BooleanisTTSWhether the message should be read aloud by Discord or not.
Discord.EmbedembedThe Discord.EmbedType.Rich Discord.Embed to be sent.
Discord.RequestOptionsoptionsThe options to be used when sending the request.
Discord.AllowedMentionsallowedMentions

Specifies if notifications are sent for mentioned users and roles in the message <code data-dev-comment-type="paramref" class="paramref">text</code>. If null, all mentioned roles and users will be notified. | | Discord.MessageComponent | component | The message components to be included with this message. Used for interactions. | | Discord.Embed[] | embeds | A array of Discord.Embeds to send with this response. Max 10. |

SendFileAsync(IUser, Stream, String, String, Boolean, Embed, RequestOptions, MessageComponent, Embed[])​

Sends a file to this message channel with an optional caption.

View Source​
Declaration
public static async Task<IUserMessage> SendFileAsync(this IUser user, Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, MessageComponent component = null, Embed[] embeds = null)
Returns​

System.Threading.Tasks.Task<Discord.IUserMessage>: A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

Parameters​
TypeNameDescription
Discord.IUseruserThe user to send the DM to.
System.IO.StreamstreamThe System.IO.Stream of the file to be sent.
System.StringfilenameThe name of the attachment.
System.StringtextThe message to be sent.
System.BooleanisTTSWhether the message should be read aloud by Discord or not.
Discord.EmbedembedThe Discord.EmbedType.Rich Discord.Embed to be sent.
Discord.RequestOptionsoptionsThe options to be used when sending the request.
Discord.MessageComponentcomponentThe message component to be included with this message. Used for interactions.
Discord.Embed[]embedsA array of Discord.Embeds to send with this response. Max 10.

SendFileAsync(IUser, String, String, Boolean, Embed, RequestOptions, MessageComponent, Embed[])​

Sends a file via DM with an optional caption.

View Source​
Declaration
public static async Task<IUserMessage> SendFileAsync(this IUser user, string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, MessageComponent component = null, Embed[] embeds = null)
Returns​

System.Threading.Tasks.Task<Discord.IUserMessage>: A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

Parameters​
TypeNameDescription
Discord.IUseruserThe user to send the DM to.
System.StringfilePathThe file path of the file.
System.StringtextThe message to be sent.
System.BooleanisTTSWhether the message should be read aloud by Discord or not.
Discord.EmbedembedThe Discord.EmbedType.Rich Discord.Embed to be sent.
Discord.RequestOptionsoptionsThe options to be used when sending the request.
Discord.MessageComponentcomponentThe message component to be included with this message. Used for interactions.
Discord.Embed[]embedsA array of Discord.Embeds to send with this response. Max 10.

BanAsync(IGuildUser, Int32, String, RequestOptions)​

Bans the user from the guild and optionally prunes their recent messages.

View Source​
Declaration
public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous operation for banning a user.

Parameters​
TypeNameDescription
Discord.IGuildUseruserThe user to ban.
System.Int32pruneDaysThe number of days to remove messages from this <code data-dev-comment-type="paramref" class="paramref">user</code> for - must be between [0, 7]
System.StringreasonThe reason of the ban to be written in the audit log.
Discord.RequestOptionsoptionsThe options to be used when sending the request.