✅ 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
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Can you send the code? I need to check if you are making the HTTP request correctly
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
ty @Scarlet
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
why are botToken and userToken always empty?
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
I didn't write it because it was private information. @Scarlet
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Understood I am reading the code trying to understand the call are you using the discrd documentation to make that bot?
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
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
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Ok first do you have insmonia? I mean the app, sorry.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Download
Download Insomnia the best API Client for REST, GraphQL, GRPC and OpenAPI design tool for developers
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
Kahrolsun MasonlarOP12mo ago
There is no need for this, why do you recommend it? I made the same code before
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Because if the result is the same, it's probably a problem with the token or credentials
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
we won't be able to do this
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
Kahrolsun MasonlarOP12mo ago
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
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
did you delete de code?
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
This is very important
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
I was reading it
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
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
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Im checking the discord docs about that api
✿ Scarlet ✿
✿ Scarlet ✿12mo 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.
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
✿ Scarlet ✿
✿ Scarlet ✿12mo 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.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Im not sure if you need to do some extra steps but there is description in the documentation
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
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
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
✿ Scarlet ✿
✿ Scarlet ✿12mo 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.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Look
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
How will I achieve this? There is a way I can do it without permission.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
That's a bit more complicated. But I have a suggestion to you
✿ Scarlet ✿
✿ Scarlet ✿12mo 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.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
That's what I see everyone doing
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
how
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
I sent you a link to the documentation
✿ Scarlet ✿
✿ Scarlet ✿12mo 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.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
This is the installation guide
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
ye ınstald
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
It contains screenshots and all
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
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.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
vanity? I didn't understand that
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
discord url
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
@Deleted User Af5t6xC5 you are calling the api to get an url and send to a server?
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
Yes, when that url is empty, I want the bot I installed to detect it and put it on my own server.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
ok I'm checking here, vanity_url
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
ty
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
is your token a bot token?
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
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...
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
it needs to be a bot token to be used with Bot prefix
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
yes but I will make a user user token?
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Keep it as a bot
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
why
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
Kahrolsun MasonlarOP12mo ago
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?
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
Kahrolsun MasonlarOP12mo ago
I'll fill it in a minute
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
No description
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
@Scarlet
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
try removing that line _httpClient.DefaultRequestHeaders.Clear();
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
No description
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
Kahrolsun MasonlarOP12mo ago
okey
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
also ccing @IsNotNull, if you want to take a look too.
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
ty my frend @IsNotNull @🎄 Thinker 🎄
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
✿ Scarlet ✿
✿ Scarlet ✿12mo 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.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
that is the endpoint you are trying to call
✿ Scarlet ✿
✿ Scarlet ✿12mo 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.
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
and that is how you get bot token authorization
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
I did all of these
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
No description
IsNotNull
IsNotNull12mo 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
Kahrolsun MasonlarOP12mo ago
ye and
IsNotNull
IsNotNull12mo 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
Kahrolsun MasonlarOP12mo ago
conclusion
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
IsNotNull12mo ago
More like a policeman wearing 30 badges. At least I find that thought more comical
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
What should I do now?
IsNotNull
IsNotNull12mo ago
Change your code so that it only adds the auth header once
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
move that piece of code up
No description
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
and
IsNotNull
IsNotNull12mo ago
That is still inside the while loop
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
okey end
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
No description
IsNotNull
IsNotNull12mo ago
I'm surprised the clear call doesn't fix that in the first place. Odd
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
xd and?
IsNotNull
IsNotNull12mo ago
Maybe I'm missing some context. Are there other problems you are trying to solve?
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
No, just trying to connect with auth to a discord api endpoint
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
No description
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
this no other problems
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Try generating a new token just in case
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
I created a new one after a while but it didn't work.
IsNotNull
IsNotNull12mo ago
I'm very familiar with making HTTP calls, but not very familiar with the Discord API. Is their auth base on OAuth?
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
Yes it is that's what is weird
IsNotNull
IsNotNull12mo 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
Kahrolsun MasonlarOP12mo ago
So what should I do?
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
what is your current pfp lol
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
rat king So what should I do? So what should I do?
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
I am not sure at all, I got confused.
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
://
IsNotNull
IsNotNull12mo 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
Kahrolsun MasonlarOP12mo ago
oh ı am not money bro
IsNotNull
IsNotNull12mo ago
I understand
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
There is no error in the code, I can't understand why it doesn't work.
IsNotNull
IsNotNull12mo ago
Be realistic, there are errors in the code You can't pass an empty auth token
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
What is the error?
IsNotNull
IsNotNull12mo ago
You are missing code that configures or finds an auth token Finding an auth token requires understanding discords auth flow
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
ı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
IsNotNull12mo 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
Kahrolsun MasonlarOP12mo ago
Isn't it work? :((((
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
Kahrolsun MasonlarOP12mo ago
Please help me, I'm taking my mother to the hospital now. Can we go to work and talk? @Scarlet @🎄 Thinker 🎄 @IsNotNull
Thinker
Thinker12mo ago
why are you pinging me? I'm not even in this thread
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
help me bro
✿ Scarlet ✿
✿ Scarlet ✿12mo 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
PixxelKick12mo ago
Is there a pastebin of the code somewhere?
✿ Scarlet ✿
✿ Scarlet ✿12mo ago
.
Kahrolsun Masonlar
Kahrolsun MasonlarOP12mo ago
Hello ım coming @Scarlet Whatsaap beo
jcotton42
jcotton4212mo ago
please do not ping random people it's quite rude
Jester
Jester12mo ago
did you invite the bot to the server you are trying to message?
PixxelKick
PixxelKick12mo ago
can you properly put this on something like https://hatebin.com/ so its readable?
SG97
SG9712mo ago
they are banned
Want results from more Discord servers?
Add your server