I am using DSharpPlus but I can't access a DiscordMember/DiscordUser's display name.
How should I do it? It seems that the DiscordUser Username returns the unique identifier name, DiscordMember DisplayName does the same and DiscordMember Nickname always returns null.
For example, if I tried to get all these on my User profile I would get my DiscordUser's Username as paganoo, my DiscordMember DisplayName as paganoo and my DiscordMember Nickname as null.
How do I get a return as Pagano?
#How do I get a DiscordMember/DiscordUser correct DisplayName?
1 messages · Page 1 of 1 (latest)
Are you using v4? its only supported in v5
Is v5 already available through NuGet?
its a prerelease
Yes
there is a checkbox right next to the search bar
Should I use the last one then?
Although not stable atm
How do I do that in the prerelease version anyway?
DisplayName works as expected in nightly
I tried the same code snippet but using the prerelease version and DisplayName is returning me the wrong name
Not the actual DisplayName
Is there any difference I should be aware of in my code?
what is it returning
paganoo in my case
what does GlobalName return
What class should GlobalName be a field of?
DiscordMember doesn't have a GlobalName field
DiscordUser
Let me try
that's rather odd, it should inherit. are you sure you are running the updated version
Thats expected
##1585
Issue #1585: v5 breaking changes tracking issue - akiraveliara
both of those are going to be useful
I think I managed to change the most part but how can I handle trigger events such as the old DiscordClient.Ready and GuildMemberAdded?
see here
Another question, when I do var dMembers = dClient.GetGuildAsync(GuildId).Result.GetAllMembersAsync();
How do I get a this IAsyncEnumerable into an Enumerable?
So I can do a foreach loop on it
do an await foreach loop instead
Ooh ok
The GlobalName worked btw, tysm
I still gotta figure out how everything works
Does v5 have a release date already?
DisplayName pulls from Nickname -> GlobalName -> Username depending on which is available
no
So DisplayName should be used?
generally yeah
My code was like this:
public async Task RunAsync()
{
var configFile = new ConfigFileReader();
await configFile.ReadConfigFile();
var dConfig = new DiscordConfiguration()
{
Intents = DiscordIntents.All,
Token = configFile.BotToken,
TokenType = TokenType.Bot,
AutoReconnect = true
};
var BotClient = new DiscordClient(dConfig);
BotClient. += Client_Ready;
BotClient.GuildMemberAdded += async (client, args) =>
{
using (var db = new EvoHubContext())
{
db.Users.Add(new User()
{
Name = args.Member.Username,
DiscordId = (long)args.Member.Id
});
await db.SaveChangesAsync();
}
};
await BotClient.ConnectAsync();
await Task.Delay(-1);
}
private static Task Client_Ready(DiscordClient sender, ReadyEventArgs args)
{
return Task.CompletedTask;
}
you won't need any of those in DiscordConfiguration
Now it became this:
public async Task RunAsync()
{
var configFile = new ConfigFileReader();
await configFile.ReadConfigFile();
var builder = DiscordClientBuilder.CreateDefault(configFile.BotToken, DiscordIntents.All);
var BotClient = builder.Build();
var test = new ConverterTest();
test.ConvertDMembersToUsers(BotClient);
await BotClient.ConnectAsync();
await Task.Delay(-1);
}
token and intents are now mandatory in registering, tokentype is always bot, autoreconnect defaults to true
So can I get rid of that? Does the bot still AutoReconnects?
Oh ok, gotcha
The Event handlers are now on the builder.ConfigureEventHandlers where I have to handle all of them together? Did I get that right?
wdym by handling them all together?
So my ClientReady and GuildMemberAdded are now in builder.ConfigureEventHandlers
yes
This is the example on the website:
builder.ConfigureEventHandlers
(
b => b.HandleMessageCreated(async (s, e) =>
{
if (e.Message.Content.ToLower().StartsWith("spiderman"))
{
await e.Message.RespondAsync("I want pictures of Spiderman!");
}
})
.HandleGuildMemberAdded(OnGuildMemberAdded)
);
private Task OnGuildMemberAdded(DiscordClient sender, GuildMemberAddedEventArgs args)
{
// non-asynchronous code here
return Task.CompletedTask;
}
yes
The rest should all be the same then? Or did something else important change?
DSharpPlus.Lavalink is defunct, if you were using that
That was for voice right? I am not
SlashCommands is deprecated in favor of Commands, but it's not terribly urgent
But are you changing the way it works or are we not having SlashCommands and MenuContext commands anymore?
it looks pretty similar
🏷 migrating from slashcommands:
https://dsharpplus.github.io/DSharpPlus/articles/migration/slashcommands_to_commands.html
heres the differences
Hmm, ok
I will give it all a try and see how it goes
Wait, what would the Handler be for ClientReady now?
🏷 ready-event:
The READY event refers to Discord, not the client
tl;dr this event is fired when Discord is ready to start sending gateway events; cache (members/guilds) are populated as these events come in.
You probably want GuildDownloadCompleted instead
The Ready event on the client only signals that your client has completed a handshake with the gateway, and it's ready to start streaming payloads to you.
This isn't to say you should never use it, but for a vast majority of uses, there is no point in using this event, and it simply exists for completeness and correctness.
Gateway documentation: https://discord.dev/topics/gateway-events#ready
So I should check if GuildDownloadCompleted was triggered before doing anything, right?
Not the Ready one
One more question, is there anything I could do to simplify my code as I will be using my Bot in only one server?
Because looping around all Guilds to just find a single one isn't very efficient right?
client.Guilds[id]
Ok
What's more efficient?
client.GetGuildAsync(id).Result;
or
client.Guilds[id];
second
May I know the reason? Just for knowledge
And is the same true for guild.Members[id] vs guild.GetMemberAsync(id).Result; and every other search?
True, sorry, I was typing through Discord only, not what I usually do
it depends on what you want
guild.Members[id] will get one from cache
await guild.GetMemberAsync(id) will try to get one from cache (and is marginally slower if it does), but then make a rest request if it wasn't cached
so you're guaranteed a result, it just might take longer
second one also bcs skipCache defaults ---
Sorry, is there a way to get the DiscordMember of Bot through the DiscordClient? I couldn't find any but just asking
no, you need a guild to get a guild member object
What about the DiscordUser of Bot?
DSharpPlus.BaseDiscordClient.CurrentUser
Summary
Gets the current user.
Declaration
public DiscordUser CurrentUser { get; internal set; }
That returns me the Bot DiscordUser then?
yes
Hey, I was trying to do DiscordClient.GlobalName but its returning null. However, the Username is right. Shouldn't it be returning this, and therefore not null?
Oh nvm
But the DiscordClient.CurrentUser does not contain a field called DisplayName
because it's not a DiscordMember
Gotcha
Ty
So I just use the Username in this case or cast to DiscordMember and use DisplayName? If so, which one is more recommended?
But isn't DiscordUser castable to DiscordMember?
yes, but only if it's actually a DiscordMember object under the hood
member is always castable to user, but not vice versa
Oh I see, okay, thank you
Is there a way to do an embed with four fields with 2 columns and 2 rows?
May I ask for a tip on how to do a certain thing?
If so, for my project's purpose, I need to register DiscordMembers to a Database but which way do you recommend?
- A SlashCommand like /register @boreal hawk [params]
- A ContextMenuCommand like click on me > Apps > Register User (without params right?)
- Reacting to an emoji (the emoji being the param)
- Clicking a button (the button being the param)