Last active
January 4, 2021 16:08
-
-
Save thomasianwright/7ca4d5753ea775b2c85369d8e2995b08 to your computer and use it in GitHub Desktop.
Discord.NET example 'userinfo' command. With Spotify, rich presence & custom game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Command("userinfo")] | |
[RequireContext(ContextType.Guild, ErrorMessage = "Sorry, this command must be ran from within a server, not a DM!")] | |
public async Task UserInfoAsync(SocketGuildUser user = null) | |
{ | |
user = (SocketGuildUser) (user ?? Context.User); | |
_logger.Log(LogLevel.Warning, user.Username); | |
if (user.IsBot) | |
{ | |
await ReplyAsync("Bots are not people :D"); | |
return; | |
} | |
var embed = new EmbedBuilder {ThumbnailUrl = user.GetAvatarUrl()} | |
.AddField("Member ID", user.Id, true) | |
.AddField("Status", user.Status, true) | |
.AddField("Joined Guild", user.JoinedAt.Value.ToString("dd MMMM, yyyy"), true) | |
.AddField("Account Created", user.CreatedAt.ToString("dd MMMM, yyyy"), true) | |
.AddField("Roles", user.Roles.Count - 1, true) | |
.WithTimestamp(DateTimeOffset.Now) | |
.WithAuthor(x => | |
{ | |
x.Name = user.Username; | |
x.IconUrl = user.GetAvatarUrl(); | |
x.Url = "https://thwr.tech/"; | |
}) | |
.WithFooter(x => | |
{ | |
x.Text = $"Requested By {Context.User.Username}"; | |
x.IconUrl = Context.User.GetAvatarUrl(); | |
}) | |
.WithColor(Color.Red); | |
if (user.Activity != null) | |
{ | |
if (user.Activity is SpotifyGame spot) | |
embed.AddField("Listening To", "Spotify", true) | |
.AddField("Track", spot.TrackTitle, true) | |
.AddField("Artist(s)", string.Join(", ", spot.Artists), true) | |
.AddField("Album", spot.AlbumTitle, true) | |
.WithThumbnailUrl(spot.AlbumArtUrl) | |
.WithColor(Color.Green); | |
else if (user.Activity is CustomStatusGame statusGame) | |
embed.AddField("Activity", statusGame.Name, true) | |
.AddField("Details", statusGame.Details, true) | |
.AddField("Playing Since", statusGame.CreatedAt, true) | |
.WithColor(Color.Magenta); | |
else if (user.Activity is RichGame richGame) | |
embed.AddField("Activity", richGame.Name, true) | |
.AddField("Details", richGame.Details, true) | |
.AddField("Playing Since", richGame.Timestamps.Start.Value.ToString("hh:mm:ss tt"), true) | |
.AddField("Time Playing", | |
(DateTimeOffset.Now - richGame.Timestamps.Start).Value.ToString(@"hh\:mm\:ss"), true) | |
.WithThumbnailUrl(richGame.SmallAsset.GetImageUrl() ?? user.GetAvatarUrl()) | |
.WithColor(Color.Gold); | |
else | |
embed.AddField("Activity", user.Activity.Name ?? "None", true); | |
} | |
else | |
{ | |
embed.AddField("Activity", "None", true); | |
} | |
await ReplyAsync(embed: embed.Build()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment