#Discord Bot Custom presence
1 messages · Page 1 of 1 (latest)
so basically you need to do something like
await _client.SetGameAsync("Rick Astley", type: ActivityType.Watching);
_client being your DiscordSocketClient
You could also use SetActivityAsync to achieve the same thing, but it has a few more options. Ex Listening, Watching, Playing.
await _client.SetActivityAsync(new Game("Hunters", ActivityType.Listening, ActivityProperties.None));
I have mine in Program.cs just before Task.Delay, so it applies the status when the bot starts:
await _client.LoginAsync(TokenType.Bot, config["tokens"]);
await _client.StartAsync();
await _client.SetActivityAsync(new Game("Hunters", ActivityType.Listening, ActivityProperties.None));
await Task.Delay(-1);
wow thanks !
you would put be fore that ?
its the only Task.Delay i can find in program.cs
my bot token is just above it
yea it would make sense aha
i found that section
but
my await doesnt have the _client
ill try it without
await _client.StartAsync();
await _client.SetActivityAsync(new Game("Hunters", ActivityType.Listening,
oh
it posts the _automatically
Guys ! Thanks a whole lot
IT WORKED
i feel like a coder now
Lmaooo
cant thank you enougu
NOW THAT this is sorted
could someone help me with SendFileAsync?
basically, i setted up my bot to send a private message to user upon joining
but id love to include by discord banner under the message
i tried to post a direct link, but its showing the link + image and its ugly
apparently i could send it as a file , and add text
but im really unsure abut the process
@wary drum u laughin at me 😦 ahahaha
at least im trying, no :O?
at this pace ill be a coder in 15 years tho
seem to be doing just fine 👍
using send file would simply be something like
using var fs = new FileStream(...)
await SendFileAsync(someFileStreamYouCreated, "myfunnyfile.png", text: "message text goes here");
alternatively you could create an embed and set the ImageUrl property to the image link
I would LOVE the welcome message to be an embed
but i dont think the banner would be big enough in a embed
ok
let me try
glad I can help!
could you tell me
if im on the right track ?
(also please dont be scared of the word RAID, its a pOKEMON GO server)
Raid Shadow Legends 
no ahaha pokemon go raids bro
You're on the right track there. I personally haven't done messages in DMs, but building embeds is pretty easy once you figure out the properties.
awesome
im trying !
i wonder how to add an image that isnt local tho
oh
now im lost LOL
the problem is
private async Task OnJoin(SocketGuildUser User)
my task

Non-local images can be attached with URLs. Here's a snippet of my code:
//container list | Returns the entire array of containers, ephemerally, in an am embedded message.
[SlashCommand("list", "List all created containers")]
public async Task ListContainers()
{
string list = tupperware.getContainerList();
var embedBuilder = new EmbedBuilder()
.WithTitle("CONTΛINΞRS")
.WithThumbnailUrl("https://i.postimg.cc/524PJp4K/POGFROMMEDAWG.png")
.WithDescription(list)
.WithColor(Color.DarkTeal)
.WithFooter("© ProjectGuild")
.WithCurrentTimestamp();
await RespondAsync(embed: embedBuilder.Build(), ephemeral: true);
}

Ehh, depends on what format you want to do it in. Some people like to do it a different way, or for a different purpose. It's preference.
i think i finished my embed
now im having a question lol
How can i test it without screwing my existing bot
lmao
i didnt create a backup
ffs
its ok
i tjhink i created a baclup now
could you review my function?
I use a private repository through GitHub, so if I ever mess up I can just pull the working state 
Sure!
Does your Mac's keyboard have the backtick key(`)?
{
if (User.Guild.Id == 1011321901639016449)
{
//Send DM
await User.SendMessageAsync()
{
var embed = new EmbedBuilder
{
Title = $"Welcome to the Raiders Den {User.Mention}!",
Description = "Heres a step by step guide on how to join raids in our Server.\r\n\r\nGo to #1027702337197838417 and select (by reacting to the pokemon emote) the raids you want to be notified about.\r\n\r\nPlease Change your Server Nickname to your PokemonGo Trainer Name. (ask us if you need help)\r\n\r\nThen when you get a ping (notification) in the channel #1023744532279463988 , click the JOIN RAID green button and you will be part of the raid group!\r\n\r\nMost of the chatting and interactions happens in #1019612216279978104, feel free to come chat with us!\r\n\r\nI wish you all a lot of nice catches and, invite your friends!\r\n\r\nI invite you all to read #1028364651697807412 carefully also",
Color = new Discord.Color(47, 49, 55),
Author = new EmbedAuthorBuilder()
Name = "The Raiders Den",
IconUrl = $"{Context.Client.CurrentUser.GetAvatarUrl()}",
ThumbnailUrl = $"attachment://{https://i.ibb.co/qC0HzH9/ezgif-com-gif-maker-2.png}",
};
}```
yay
worked
please tell me if my code is uterly shitty
lmao
ok so
private is a problem
apparently
i tried to rebuild it and it fails
well it succeded to rebuild
but it gives me error
I mean it's messy with the Description, but, luckily there's a way around that. In one of my bots I have a text file called help.txt. help.txt has all of that random stuff, whereas my code looks like this:
//Open and read help.txt asynchronusly.
[SlashCommand("elp", "Show some tips and the link to the manual")]
public async Task ElpCommmand()
{
String result;
using (StreamReader reader = File.OpenText("help.txt"))
{
result = await reader.ReadToEndAsync();
reader.Dispose();
reader.Close();
}
await RespondAsync(result, ephemeral: true);
Change it to be public 
Otherwise your code looks alright 
so weird
thats where the .exe was before
now thats nothing lmao
hm
how is it possible
there used to have all this in this folder
You may want to use that backup...
Okay good.
My guess is something else code-wise got deleted in that process, but you should be fine to make the embed again 
hm
im sure not because
i did not restore backup
i basically control z
until i was at step 1

aha
when i rebuilt the code
they gave me a lot of weird error about my task and all
i know im a pain bro sorry
maybe my task should be
Just a tought
private async Task OnJoin(SocketGuildUser User)
{
if (User.Guild.Id == 1011321901639016449)
{
//Send DM
await User.SendMessageAsync
could the embed not work
with this?
Not if it is private, make sure its public.
is it an issue that all my other thing are private ?
i made it public and it was still broken
No no, stuff like your InteractionHandler's functions should be private. Functions, in this case, your OnJoin Task should be public, since other parts of your code need to access it. Does that make sense?
Solid 
but should User.SendMessageAsync()
should be somethinbg else for an embed ?
it only gives me sendmessage or sendfile option
Not sure why it's not showing you SendMessageAsync as an option.
Come to think of it, you're missing a curly bracket in this code. Should be something like:
public async Task OnJoin(SocketGuildUser User)
{
if (User.Guild.Id == 1011321901639016449)
{
//Send DM
await User.SendMessageAsync()
{
var embed = new EmbedBuilder
{
Title = $"Welcome to the Raiders Den {User.Mention}!",
Description = "Heres a step by step guide on how to join raids in our Server.\r\n\r\nGo to #1027702337197838417 and select (by reacting to the pokemon emote) the raids you want to be notified about.\r\n\r\nPlease Change your Server Nickname to your PokemonGo Trainer Name. (ask us if you need help)\r\n\r\nThen when you get a ping (notification) in the channel #1023744532279463988 , click the JOIN RAID green button and you will be part of the raid group!\r\n\r\nMost of the chatting and interactions happens in #1019612216279978104, feel free to come chat with us!\r\n\r\nI wish you all a lot of nice catches and, invite your friends!\r\n\r\nI invite you all to read #1028364651697807412 carefully also",
Color = new Discord.Color(47, 49, 55),
Author = new EmbedAuthorBuilder()
Name = "The Raiders Den",
IconUrl = $"{Context.Client.CurrentUser.GetAvatarUrl()}",
ThumbnailUrl = $"attachment://{https://i.ibb.co/qC0HzH9/ezgif-com-gif-maker-2.png}",
};
}
}
ohhh
await FollowupAsync(embed: EmbedBuilder.Build());
should this be at the end of the embed builder ?
its there for all my other embed
Yep! That actually "sends" the embed.
Make sure you count how many curly brackets you have "open" { and "closed" } . If they're ever not the same, something's not right 
ohhh
oki
for some reason
it doesnt look right
lmao
i think FollowupAsync should pop yellow
if it was actually working
Well... did you count your curly brackets
❓
let me rethink of it
1 sec
i dont understand curly bracket yet i think
i see one there open
actually i see 3 open
there
and 3 closed there
Technically, you have four, and only three are closed.
public async Task OnJoin(SocketGuildUser User)
{
if (User.Guild.Id == 1011321901639016449)
{
//Send DM
await User.SendMessageAsync()
{
var embed = new EmbedBuilder
{
Title = $"Welcome to the Raiders Den {User.Mention}!",
Description = "Heres a step by step guide on how to join raids in our Server.\r\n\r\nGo to #1027702337197838417 and select (by reacting to the pokemon emote) the raids you want to be notified about.\r\n\r\nPlease Change your Server Nickname to your PokemonGo Trainer Name. (ask us if you need help)\r\n\r\nThen when you get a ping (notification) in the channel #1023744532279463988 , click the JOIN RAID green button and you will be part of the raid group!\r\n\r\nMost of the chatting and interactions happens in #1019612216279978104, feel free to come chat with us!\r\n\r\nI wish you all a lot of nice catches and, invite your friends!\r\n\r\nI invite you all to read #1028364651697807412 carefully also",
Color = new Discord.Color(47, 49, 55),
Author = new EmbedAuthorBuilder()
Name = "The Raiders Den",
IconUrl = $"{Context.Client.CurrentUser.GetAvatarUrl()}",
ThumbnailUrl = $"attachment://{https://i.ibb.co/qC0HzH9/ezgif-com-gif-maker-2.png}",
};
}
}
}
This should be good 
ohhhh
Come to think of it, what are you trying to do again?
i had 4 !
what do you mean
look
so let me explain

when a member joined my server, i had dyno DM that user with intrusctions
but i tought id be nicer if my own bot was doing it
Okay gotcha.
and i succeded
that was the result from yesterday
but i wanted my banner at the end of the message
and that link wasnt going away
so i tought of an embed
i also think embed is cleaner
But for some reason it doesnt work
So at this point, we're just trying to get the embed to work, right?
yes hihi
ok so
the error list is getting smaller
we started at 16
now 5
lmao
it says that embedbuilder doesnt contain a definition for 'Name'
and 'IconUrl'
Let's clear some more here. So, in this case, you were trying to send the embed before the embed was even made. Here's what I came up with:
public async Task OnJoin(SocketGuildUser User)
{
if (User.Guild.Id == 1011321901639016449)
{
//Send DM
{
var embed = new EmbedBuilder
{
Title = $"Welcome to the Raiders Den {User.Mention}!",
Description = "Heres a step by step guide on how to join raids in our Server.\r\n\r\nGo to #1027702337197838417 and select (by reacting to the pokemon emote) the raids you want to be notified about.\r\n\r\nPlease Change your Server Nickname to your PokemonGo Trainer Name. (ask us if you need help)\r\n\r\nThen when you get a ping (notification) in the channel #1023744532279463988 , click the JOIN RAID green button and you will be part of the raid group!\r\n\r\nMost of the chatting and interactions happens in #1019612216279978104, feel free to come chat with us!\r\n\r\nI wish you all a lot of nice catches and, invite your friends!\r\n\r\nI invite you all to read #1028364651697807412 carefully also",
Color = new Discord.Color(47, 49, 55),
Author = new EmbedAuthorBuilder(),
Name = "The Raiders Den",
IconUrl = $"{Context.Client.CurrentUser.GetAvatarUrl()}",
ThumbnailUrl = $"attachment://{https://i.ibb.co/qC0HzH9/ezgif-com-gif-maker-2.png}"
};
await User.SendMessageAsync(embed: embed.Build());
}
}
}
they seem to have a problem with that part
it says that 'Context' Doesnt exist in the actual context
i basically copied that part from an existing embed
hm
Check out the Embed documentation: https://discordnet.dev/api/Discord.Embed.html
I think your "Name" should be "Title", and the "IconUrl" "Thumbnail".
I think 
Well, maybe not.
What's the purpose of "Name"?
I think I see the issue.
i still need to understand what that context is
The idea there is, your program needs to know where to look for the data you want.
Context only exists in command modules
if you just need the current user, I think it's also available on the guild
ok ty
i will try to understand that information now
let me show you
that whole author thing
its what its showing on embed
and that logo is my bot avatar
yeah, so access the CurrentUser property on the SocketGuild object.
you can get the guild form the SocketGuildUser object
nope, you need an instance of the class, not the class itself
oh
use the user parameter that's provided by the event
the event gives you this
grab the guild from that and the current user from the guild
yeah
OnJoin(SocketGuildUser User) <-- the User here is an object of type SocketGuildUser
Ok !
so just how you do User.Guild.Id to get the Id of the guild
you want to now get CurrentUser from the guild
Pretty much like this:
Author = new EmbedAuthorBuilder() { Name = "The Raiders Den", IconUrl = $"{User.Guild.CurrentUser}" },
the only difference between the 2 is where u get the author data from
the embed doesn't care where u get it from
Its also because they're in a different place in your code. In this case, you're sending this embed from an action that happens, and not a command.
i see !!
yea
the other wmebed is triggered from a slash command
and gets the data from a database
you don't need attachment if you are using a url
Yep! In the context of the slash command, it knows that the User, through the client, is the person that executed the command, if that makes sense.
IT does
you guys are really helpful
i wish to become great one day
i have close to no education and english isnt my main language
but i really love all that and wanna become good
my 30 years old brain got slowed down by all the abuse i did in my previous life lol
but im sure ill manage one day
and english isnt my main language
would not have guessed that
aha i appreciate that
i learned from video games
i found some old post on forums that i did like 15 years ago
i cant even understand myself in these post 
since i dont need atachement
this would work
hm
down to 1 error
but 13 warning
lmao
apparently they are wanting a ; here
wich is weird
i dont get it LOL
i rebuilt the code
and it still send that 
await FollowupAsync(embed: EmbedBuilder.Build());
i definity forgot to add this at the end but
FollowupAsync doesnt seem to be working
ohhh
maybe i had to do that ?
preatty sure that doesnt work either
I DID IT !
god damn that was hard
but, now, the mention doesnt work and the thumbnail is ugly lmao
did you intent to use the thumbnailUrl instead of ImageUrl?
Oh i see
in description it should work?
or since its description
i should just do {User}
it should work
but that highlight suggests that you are missing the $ in the front of the string
the same $ thing that's here
its crazy
we did it bpoys
thanks a lot
Can the ImageUrl
be a gif ?
my gif turned into a static image
odd tho
even if you guys hand holded me a bit
im pretty proud lmao
its the first function i (code myself)
i mean
hand holded me a LOT
but still
lol
In janky psedocode:
- Input a
doubletime with the commands (a certain time? Depends on what you're counting for or to) - Have the bot count that amount of time in some way
- Display the time being counted (maybe)
- Have the bot announce the time
I've seen some bots where you have to input milliseconds. Live Countdown is a bot that does that kind of thing, but you might be able to find code/reverse-engineer based off of that. I've never tried it so I don't know 
i wanted to add the /countdown command from live countdown aha
to my bot
Just output a relative timestamp...it will countdown on its own
what do you mean?
i didnt want to mess with unix timestamp
i know the <t:unix:R> thing
but id rather my bot do it aha we have to use it too often
Ok, but how often would your bot be refreshing the visual counter?
Im sorry man
i always have question and end up being ok with it
well the bot would use unix timestamp for sure
but i wanted it to generate them for me