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