C
C#2y ago
bLanco

❔ I wrote a discord bot but it's not answering me ?

using DSharpPlus;
using DSharpPlus.EventArgs;
using System.Threading.Tasks;

class Program
{
static DiscordClient discord;

static void Main(string[] args)
{
MainAsync().ConfigureAwait(false).GetAwaiter().GetResult();
}

static async Task MainAsync()
{
discord = new DiscordClient(new DiscordConfiguration
{
Token = "MTA5NzI0MDEyODA4MDA3Mjc3NQ.GJawtS.2odUYCCE4EGZwvHWso6G9mmyrGk9LqUB07HeVc",
TokenType = TokenType.Bot,
Intents = DiscordIntents.AllUnprivileged
});

discord.MessageCreated += async (s, e) =>
{
if (e.Message.Content.ToLower().StartsWith("!ping"))
{
await e.Message.RespondAsync("@here");
}
};

await discord.ConnectAsync();
await Task.Delay(-1);
}
}
using DSharpPlus;
using DSharpPlus.EventArgs;
using System.Threading.Tasks;

class Program
{
static DiscordClient discord;

static void Main(string[] args)
{
MainAsync().ConfigureAwait(false).GetAwaiter().GetResult();
}

static async Task MainAsync()
{
discord = new DiscordClient(new DiscordConfiguration
{
Token = "MTA5NzI0MDEyODA4MDA3Mjc3NQ.GJawtS.2odUYCCE4EGZwvHWso6G9mmyrGk9LqUB07HeVc",
TokenType = TokenType.Bot,
Intents = DiscordIntents.AllUnprivileged
});

discord.MessageCreated += async (s, e) =>
{
if (e.Message.Content.ToLower().StartsWith("!ping"))
{
await e.Message.RespondAsync("@here");
}
};

await discord.ConnectAsync();
await Task.Delay(-1);
}
}
Is there any wrong code or something else? And if there's no bug's in code maybe I couldn't authorize my bot to server. Do you guys know any tutorial for this or can you guys teach me how to add?
4 Replies
Buddy
Buddy2y ago
Regenerate the bot token immediately As now it has been exposed in a public discord, in a public channel.
occluder
occluder2y ago
You need DiscordIntents.MessageContents in the intents too. So it would be DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents. Also do what the guy above me said lol
jcotton42
jcotton422y ago
You also need message content enabled in the bot portal
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server