✅ My bot isn't working

ChatGPT definition of bot Your provided C# program appears to be a Discord bot that periodically checks the information of a specified guild and sends a message to a webhook if a vanity URL is taken. Here's an explanation of the main components: Main Method: It initializes variables, including botToken, userToken, and guildId. Enters an infinite loop where it calls the GetGuildInfo method and sends a message if a vanity URL is taken. Delays for 65 milliseconds in each iteration using Task.Delay. GetGuildInfo Method: Clears default request headers and adds the "Authorization" header with the provided bot token. Sends a GET request to the Discord API to retrieve information about the specified guild. Checks if the request is successful, and if so, reads the response and checks if the guild has a vanity URL. Prints the guild name and description to the console. Handles exceptions and prints an error message if any occur. SendMessage Method: Sends a POST request to a Discord webhook with a JSON payload containing a username and message. Checks if the request is successful and prints a success message, otherwise prints an error message. Please note that the botToken and userToken variables are initialized as empty strings in your code. You need to replace them with the actual tokens for your bot and user. Additionally, the program uses an infinite loop with a delay. Ensure that your application can be terminated gracefully (e.g., by handling signals) if needed. ChatGPT definition of bot
No description
120 Replies
Raven Scarlet
Raven Scarlet6mo ago
Can you send the code? I need to check if you are making the HTTP request correctly
Kahrolsun Masonlar
ty @Scarlet
Raven Scarlet
Raven Scarlet6mo ago
why are botToken and userToken always empty?
Kahrolsun Masonlar
I didn't write it because it was private information. @Scarlet
Raven Scarlet
Raven Scarlet6mo ago
Understood I am reading the code trying to understand the call are you using the discrd documentation to make that bot?
Kahrolsun Masonlar
This is a kind of console software, that is, it is not exactly Discord. It is a code with two tokens. It monitors the Discord servers where you enter a token. When the vanities run out, it transfers it to your server. @Scarlet
Raven Scarlet
Raven Scarlet6mo ago
Ok first do you have insmonia? I mean the app, sorry.
Raven Scarlet
Raven Scarlet6mo ago
Download
Download Insomnia the best API Client for REST, GraphQL, GRPC and OpenAPI design tool for developers
Raven Scarlet
Raven Scarlet6mo ago
Insomnia ^^^^ With this program you can test your HTTP call manually I want you to get the token/user and test the url through insomnia so you will know that the problem maybe is not the code itself
Kahrolsun Masonlar
There is no need for this, why do you recommend it? I made the same code before
Raven Scarlet
Raven Scarlet6mo ago
Because if the result is the same, it's probably a problem with the token or credentials
Kahrolsun Masonlar
we won't be able to do this
Raven Scarlet
Raven Scarlet6mo ago
but if you are able to do it through insomnia maybe you are missing something in the code Can you send me the API docs? I need to check if you are filling what is needed to connect through the code.
Kahrolsun Masonlar
The code is not wrong, error in one package I don't have an API document, you have to tell me what I need to create. pls help bro
Raven Scarlet
Raven Scarlet6mo ago
did you delete de code?
Kahrolsun Masonlar
This is very important
Raven Scarlet
Raven Scarlet6mo ago
I was reading it
Kahrolsun Masonlar
using System; using System.Net.Http; using System.Net.Http.Json; using System.Text; using System.Text.Json; using System.Threading.Tasks; class Program { private static readonly HttpClient _httpClient = new HttpClient(); private static string _webhookUrl = "https://discord.com/api/webhooks/1186970862117732474/u2QF63NWth7L1r4STT1BcH0A_IrtXMXiNeiqI97oau5CwjiV2rNNREyGxwWfTJ37GDc8"; private static bool _vanityUrlTaken = false; static async Task Main() { string botToken = ""; string userToken = ""; string guildId = "1186950317150060614"; while (true) { await GetGuildInfo(userToken, guildId, botToken); if (_vanityUrlTaken) { await SendMessage(_webhookUrl, "Gizli sniper", "aldım"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Başarıyla 'aldım' mesajı gönderildi."); Console.ResetColor(); _vanityUrlTaken = false; } await Task.Delay(65); } } static async Task GetGuildInfo(string userToken, string guildId, string botToken) { try { _httpClient.DefaultRequestHeaders.Clear(); _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bot {botToken}"); HttpResponseMessage response = await _httpClient.GetAsync($"https://discord.com/api/guilds/{guildId}", HttpCompletionOption.ResponseHeadersRead); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, }; var result = await response.Content.ReadFromJsonAsync<dynamic>(options); if (!string.IsNullOrEmpty(result?.vanity_url)) { _vanityUrlTaken = true; } Console.WriteLine($"Guild Name: {result?.name}"); Console.WriteLine($"Guild Description: {result?.description}"); } else { Console.WriteLine($"Error: {response.StatusCode} - {await response.Content.ReadAsStringAsync()}"); } } catch (Exception ex) { Console.WriteLine($"An error occurred: {ex.Message}"); } } static async Task SendMessage(string webhookUrl, string username, string message) { try { var payload = new { username = username, content = message }; var jsonPayload = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpClient.PostAsync(webhookUrl, jsonPayload); if (response.IsSuccessStatusCode) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Mesaj başarıyla gönderildi."); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Mesaj gönderme başarısız. Durum kodu: {response.StatusCode}"); Console.WriteLine($"Error: {response.StatusCode} - {await response.Content.ReadAsStringAsync()}"); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Bir hata oluştu: {ex.Message}"); } } } this @Scarlet
Raven Scarlet
Raven Scarlet6mo ago
Im checking the discord docs about that api
Raven Scarlet
Raven Scarlet6mo ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
Raven Scarlet
Raven Scarlet6mo ago
You are calling an endpoint with no auth headers HttpResponseMessage response = await _httpClient.GetAsync($"https://discord.com/api/guilds/%7BguildId%7D", HttpCompletionOption.ResponseHeadersRead); That line make sure the _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bot {botToken}"); is right
Raven Scarlet
Raven Scarlet6mo ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
Raven Scarlet
Raven Scarlet6mo ago
Im not sure if you need to do some extra steps but there is description in the documentation
Kahrolsun Masonlar
Dude, I'm not a complete C# software developer, I'm taking courses right now, can you help me? Can I do this via a user rather than a bot? @Scarlet
Raven Scarlet
Raven Scarlet6mo ago
Be calm This is the discord doc, not related with C# at all I don't know if you can do this as a user, you can check that on the permissions page
Raven Scarlet
Raven Scarlet6mo ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
Raven Scarlet
Raven Scarlet6mo ago
Look
Kahrolsun Masonlar
How will I achieve this? There is a way I can do it without permission.
Raven Scarlet
Raven Scarlet6mo ago
That's a bit more complicated. But I have a suggestion to you
Raven Scarlet
Raven Scarlet6mo ago
Instead of calling the API directly, why not just use the library? https://discordnet.dev/guides/introduction/intro.html
Discord.Net Docs
Introduction to Discord.Net | Discord.Net Documentation
Welcome! Before you dive into this library, however, you should have some decent understanding of the language you are about to use.
Raven Scarlet
Raven Scarlet6mo ago
That's what I see everyone doing
Kahrolsun Masonlar
how
Raven Scarlet
Raven Scarlet6mo ago
I sent you a link to the documentation
Raven Scarlet
Raven Scarlet6mo ago
Discord.Net Docs
Installing Discord.Net | Discord.Net Documentation
Discord.Net is distributed through the NuGet package manager; the most recommended way for you to install this library.
Raven Scarlet
Raven Scarlet6mo ago
This is the installation guide
Kahrolsun Masonlar
ye ınstald
Raven Scarlet
Raven Scarlet6mo ago
It contains screenshots and all
Kahrolsun Masonlar
What I can write is not in the library. What I want to write is to send a get request to the Discord API, the server should select its vanity, then the thoughts of emptying this selected vanity, pull that vanity with httppatch and branch to the server.
Raven Scarlet
Raven Scarlet6mo ago
vanity? I didn't understand that
Kahrolsun Masonlar
discord url
Raven Scarlet
Raven Scarlet6mo ago
@Deleted User Af5t6xC5 you are calling the api to get an url and send to a server?
Kahrolsun Masonlar
Yes, when that url is empty, I want the bot I installed to detect it and put it on my own server.
Raven Scarlet
Raven Scarlet6mo ago
ok I'm checking here, vanity_url
Kahrolsun Masonlar
ty
Raven Scarlet
Raven Scarlet6mo ago
is your token a bot token?
Kahrolsun Masonlar
Mokali Music
YouTube
Alizade x Lvbel C5 x 50 Cent - Just Yallah (Ups & Mokali Remix)
►Tüm Şarkılar ve Albümler Spotify: https://open.spotify.com/artist/7zQSDsbBTvsn4RxrsKMvcP?si=6qm89NeMTwKAbAhytemwzQ 📢 Bana destek olmak için beğen butonuna basmayı lütfen unutmayın güzel insanlar 👍 ❤ ❤ ❤ ►Yeni videolardan bildirim almak ve haberdar olmak için 🔔 ZİL butonuna basarak bildirimleri açabilirsiniz. ►VE TABİKİ ABONE OLMAYI UNUTMAY...
Raven Scarlet
Raven Scarlet6mo ago
it needs to be a bot token to be used with Bot prefix
Kahrolsun Masonlar
yes but I will make a user user token?
Raven Scarlet
Raven Scarlet6mo ago
Keep it as a bot
Kahrolsun Masonlar
why
Raven Scarlet
Raven Scarlet6mo ago
Check the value of your botToken variable to see if it is not coming null if you make it a user it is agains discord ToS
Kahrolsun Masonlar
Two tokens will come, one piece is my server, another is the wanted server, the one is mine, will that be the bot that will pull it to me?
Raven Scarlet
Raven Scarlet6mo ago
and if you automate with a user you will get banned probably keep it as a bot check the value of your botToken I think it is coming null or wrong
Kahrolsun Masonlar
I'll fill it in a minute
Kahrolsun Masonlar
@Scarlet
Raven Scarlet
Raven Scarlet6mo ago
try removing that line _httpClient.DefaultRequestHeaders.Clear();
Raven Scarlet
Raven Scarlet6mo ago
Ok, put it back, Ill ping a person to see if they can see a problem that I am unable to see @🎄 Thinker 🎄 can you see any flaw in that http client call? I am checking but can't see anything wrong
Kahrolsun Masonlar
okey
Raven Scarlet
Raven Scarlet6mo ago
also ccing @IsNotNull, if you want to take a look too.
Kahrolsun Masonlar
ty my frend @IsNotNull @🎄 Thinker 🎄
Raven Scarlet
Raven Scarlet6mo ago
just wait, they're probably busy or don't know how to help anyways, I am searching here, have you read the discord api documentation? the basics at least, I recommend doing so
Raven Scarlet
Raven Scarlet6mo ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
Raven Scarlet
Raven Scarlet6mo ago
that is the endpoint you are trying to call
Raven Scarlet
Raven Scarlet6mo ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
Raven Scarlet
Raven Scarlet6mo ago
and that is how you get bot token authorization
Kahrolsun Masonlar
I did all of these
IsNotNull
IsNotNull6mo ago
Your http client is static, which is fine. You don't want to create it for every request. However, inside your while loop you are calling GetGuildInfo, which adds default headers. That means you are adding multiple auth headers to the http clients default headers.
Kahrolsun Masonlar
ye and
IsNotNull
IsNotNull6mo ago
The server is responsing by saying "What am I supposed to do with 20+ auth headers? I will only handle if one exists"
Kahrolsun Masonlar
conclusion
Raven Scarlet
Raven Scarlet6mo ago
you are trying to arrest a criminal with 30+ policemen trying to enter the police station at the same time then the other cop inside it is looking to you all like that: 🤨
IsNotNull
IsNotNull6mo ago
More like a policeman wearing 30 badges. At least I find that thought more comical
Kahrolsun Masonlar
What should I do now?
IsNotNull
IsNotNull6mo ago
Change your code so that it only adds the auth header once
Raven Scarlet
Raven Scarlet6mo ago
move that piece of code up
No description
Kahrolsun Masonlar
and
IsNotNull
IsNotNull6mo ago
That is still inside the while loop
Kahrolsun Masonlar
okey end
IsNotNull
IsNotNull6mo ago
I'm surprised the clear call doesn't fix that in the first place. Odd
Kahrolsun Masonlar
xd and?
IsNotNull
IsNotNull6mo ago
Maybe I'm missing some context. Are there other problems you are trying to solve?
Raven Scarlet
Raven Scarlet6mo ago
No, just trying to connect with auth to a discord api endpoint
Kahrolsun Masonlar
this no other problems
Raven Scarlet
Raven Scarlet6mo ago
Try generating a new token just in case
Kahrolsun Masonlar
I created a new one after a while but it didn't work.
IsNotNull
IsNotNull6mo ago
I'm very familiar with making HTTP calls, but not very familiar with the Discord API. Is their auth base on OAuth?
Raven Scarlet
Raven Scarlet6mo ago
Yes it is that's what is weird
IsNotNull
IsNotNull6mo ago
Many modern auth schemes require you to authenticate to get a refresh token that can be used to call an endpoint to get an access token. The access token is usually what is sent in an auth header, but it usually expires after a short time. In other schemes you might have a longer lived opaque token. No matter what, passing a blank token will never work (or at least, never 'should')
Kahrolsun Masonlar
So what should I do?
Raven Scarlet
Raven Scarlet6mo ago
what is your current pfp lol
Kahrolsun Masonlar
rat king So what should I do? So what should I do?
Raven Scarlet
Raven Scarlet6mo ago
I am not sure at all, I got confused.
Kahrolsun Masonlar
://
IsNotNull
IsNotNull6mo ago
It sounds like you are are trying to solve a problem that you don't understand without learning how it works? Maybe pay someone to write the code, or try to find a Discord bot library that wraps up the auth part of it for you?
Kahrolsun Masonlar
oh ı am not money bro
IsNotNull
IsNotNull6mo ago
I understand
Kahrolsun Masonlar
There is no error in the code, I can't understand why it doesn't work.
IsNotNull
IsNotNull6mo ago
Be realistic, there are errors in the code You can't pass an empty auth token
Kahrolsun Masonlar
What is the error?
IsNotNull
IsNotNull6mo ago
You are missing code that configures or finds an auth token Finding an auth token requires understanding discords auth flow
Kahrolsun Masonlar
ıt's not empty anyway, I emptied it because I took the size Add your friends everywhere and let them take a look too.
IsNotNull
IsNotNull6mo ago
I emptied it because I took the size
Can you rephrase that? I understand the words, but don't see the relation between empying and taking the size
Kahrolsun Masonlar
Isn't it work? :((((
Raven Scarlet
Raven Scarlet6mo ago
He removed to post here The token is in there He have the token he just removes to post the code here in the chat
Kahrolsun Masonlar
Please help me, I'm taking my mother to the hospital now. Can we go to work and talk? @Scarlet @🎄 Thinker 🎄 @IsNotNull
Thinker
Thinker6mo ago
why are you pinging me? I'm not even in this thread
Kahrolsun Masonlar
help me bro
Raven Scarlet
Raven Scarlet6mo ago
I unfortunately don't know how to help I don't know the discord api much This is not a c# question anymore I think you need support from a discord bot community
PixxelKick
PixxelKick6mo ago
Is there a pastebin of the code somewhere?
Raven Scarlet
Raven Scarlet6mo ago
.
Kahrolsun Masonlar
Hello ım coming @Scarlet Whatsaap beo
jcotton42
jcotton426mo ago
please do not ping random people it's quite rude
Jester
Jester6mo ago
did you invite the bot to the server you are trying to message?
PixxelKick
PixxelKick6mo ago
can you properly put this on something like https://hatebin.com/ so its readable?
SG97
SG976mo ago
they are banned