#Discord Bot Custom presence

1 messages · Page 1 of 1 (latest)

topaz adder
#

so basically you need to do something like

await _client.SetGameAsync("Rick Astley", type: ActivityType.Watching);
#

_client being your DiscordSocketClient

sterile barn
#

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);
high thunder
#

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

high thunder
#

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

wary drum
#

seem to be doing just fine 👍

high thunder
#

thanks man ❤️

#

i really love all these stuff

wary drum
#

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

high thunder
#

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

sterile barn
high thunder
#

could you tell me

#

if im on the right track ?

#

(also please dont be scared of the word RAID, its a pOKEMON GO server)

sterile barn
#

Raid Shadow Legends monkaW

high thunder
#

no ahaha pokemon go raids bro

sterile barn
# high thunder

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.

high thunder
#

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

sterile barn
#

Kekw
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);
        }
high thunder
#

oh man thanks

#

ok lets try

sterile barn
high thunder
#

im wondering one thing

#

should i use .WithTitle

#

instead of Title = ?

sterile barn
#

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.

high thunder
#

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?

sterile barn
#

I use a private repository through GitHub, so if I ever mess up I can just pull the working state PepeLaugh

sterile barn
high thunder
#

awesome

#

well

#

im on my work mac

#

and idk how to do the intent

#

lmao

sterile barn
#

Does your Mac's keyboard have the backtick key(`)?

high thunder
#
        {
            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

sterile barn
#

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);
sterile barn
#

Otherwise your code looks alright SeemsGood

high thunder
#

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

sterile barn
#

You may want to use that backup...

high thunder
#

LOL

#

yea

#

with backup

#

everything came back

sterile barn
#

Okay good.

high thunder
#

basically i just reverted to old message

#

instead of embed

sterile barn
#

My guess is something else code-wise got deleted in that process, but you should be fine to make the embed again Shrug

high thunder
#

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?

sterile barn
#

Not if it is private, make sure its public.

high thunder
#

is it an issue that all my other thing are private ?

#

i made it public and it was still broken

sterile barn
#

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?

high thunder
#

yes

#

totally

#

thanks a lot

#

ok

#

let me retry lol

sterile barn
#

Solid pepethumb

high thunder
#

but should User.SendMessageAsync()

#

should be somethinbg else for an embed ?

#

it only gives me sendmessage or sendfile option

sterile barn
# high thunder ``` private async Task OnJoin(SocketGuildUser User) { ...

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}",
                    };

                }
            }
high thunder
#

ohhh

#

await FollowupAsync(embed: EmbedBuilder.Build());

#

should this be at the end of the embed builder ?

#

its there for all my other embed

sterile barn
#

Yep! That actually "sends" the embed.

high thunder
#

Ok ❤️

#

😄

sterile barn
#

Make sure you count how many curly brackets you have "open" { and "closed" } . If they're ever not the same, something's not right moon2LOLE

high thunder
#

ohhh

#

oki

#

for some reason

#

it doesnt look right

#

lmao

#

i think FollowupAsync should pop yellow

#

if it was actually working

sterile barn
#

Well... did you count your curly brackets moon2S

high thunder
#

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

sterile barn
#

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 moon2S

high thunder
#

ohhhh

sterile barn
#

Come to think of it, what are you trying to do again?

high thunder
#

i had 4 !

high thunder
#

look

#

so let me explain

sterile barn
high thunder
#

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

sterile barn
#

Okay gotcha.

high thunder
#

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

sterile barn
#

So at this point, we're just trying to get the embed to work, right?

high thunder
#

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'

sterile barn
#

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());
                }
            }
        }
high thunder
#

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

sterile barn
#

I think your "Name" should be "Title", and the "IconUrl" "Thumbnail".

#

I think moon2S

#

Well, maybe not.

high thunder
#

so weird that it works

#

on my other embed aha

sterile barn
#

What's the purpose of "Name"?

high thunder
#

this embedbuilder

#

works

#

oh wait

#

its all in the same line

#

lmao

sterile barn
#

I think I see the issue.

high thunder
#

basically its part of author

#

im not good enoug to see it BUT

high thunder
sterile barn
#

The idea there is, your program needs to know where to look for the data you want.

high thunder
#

thats from the working embed

#

so in this case it gets the context

#

ok

wary drum
#

Context only exists in command modules

#

if you just need the current user, I think it's also available on the guild

high thunder
#

i might be too mentally limited for that

#

and let coders do coding

#

lmao

high thunder
#

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

wary drum
#

yeah, so access the CurrentUser property on the SocketGuild object.

#

you can get the guild form the SocketGuildUser object

high thunder
#

like this? 😄

#

it showed colors

#

its a good sign

#

LOL

wary drum
#

nope, you need an instance of the class, not the class itself

high thunder
#

oh

wary drum
#

use the user parameter that's provided by the event

wary drum
#

grab the guild from that and the current user from the guild

high thunder
#

ohh

#

its all part of this ?

wary drum
#

yeah

#

OnJoin(SocketGuildUser User) <-- the User here is an object of type SocketGuildUser

high thunder
#

Ok !

wary drum
#

so just how you do User.Guild.Id to get the Id of the guild

#

you want to now get CurrentUser from the guild

sterile barn
#

Pretty much like this:

Author = new EmbedAuthorBuilder() { Name = "The Raiders Den", IconUrl = $"{User.Guild.CurrentUser}" },
high thunder
#

ohhh

#

damn

#

why is it not like that

#

on the other embed

#

thats why im lost

wary drum
#

the only difference between the 2 is where u get the author data from

#

the embed doesn't care where u get it from

high thunder
#

i see !

sterile barn
#

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.

high thunder
#

yea

#

the other wmebed is triggered from a slash command

#

and gets the data from a database

wary drum
#

you don't need attachment if you are using a url

sterile barn
#

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.

high thunder
#

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

wary drum
#

and english isnt my main language
would not have guessed that

high thunder
#

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 kek

#

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

high thunder
#

i dont get it LOL

#

i rebuilt the code

#

and it still send that kekw

#

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

high thunder
#

I DID IT !

#

god damn that was hard

#

but, now, the mention doesnt work and the thumbnail is ugly lmao

wary drum
#

did you intent to use the thumbnailUrl instead of ImageUrl?

high thunder
#

i wanted image

#

ok

#

lets retry

wary drum
#

you can't mention in the title or field names

#

only description or field values

high thunder
#

Oh i see

#

in description it should work?

#

or since its description

#

i should just do {User}

wary drum
#

it should work

#

but that highlight suggests that you are missing the $ in the front of the string

high thunder
#

but better but not mentionning

#

oh

#

i see !!

#

whats that $ thing

wary drum
high thunder
#

its crazy

#

we did it bpoys

#

thanks a lot

#

Can the ImageUrl

#

be a gif ?

#

my gif turned into a static image

wary drum
#

yeah

#

gis should work

high thunder
#

it doesnt but for real its nop

#

its np**

#

not gonna lie

wary drum
#

odd tho

high thunder
#

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

wary drum
#

lol

high thunder
#

Guys

#

do you have an idea how i could introduce a countdown command to my bot

sterile barn
#

In janky psedocode:

  • Input a double time 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 Pepeg

high thunder
#

to my bot

wary drum
#

Just output a relative timestamp...it will countdown on its own

high thunder
#

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

wary drum
#

Ok, but how often would your bot be refreshing the visual counter?

high thunder
#

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

high thunder
#

Hello guys !

#

Im back with another question