Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

discord.net - Discord bot multiserver

I am creating a Discord bot that should send messages to hundreds of servers in parallel.

What should I use for this?

Now I tried doing it with C# and Discord.Net. And I can send messages like this

var client = new DiscordSocketClient();

Login(_client, BotToken).GetAwaiter().GetResult();

var Current_guild = guilds.FirstOrDefault(u =>u.Id == server_id);
var channel = Current_guild.Channels.FirstOrDefault(u =>u.Name.Equals(channel_name, StringComparison.InvariantCultureIgnoreCase))

channel.SendMessageAsync(message).GetAwaiter().GetResult();

private async Task < bool > Login(DiscordSocketClient client, string bot_token) {
  var result = false;

  var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));

  try {
    await client.LoginAsync(TokenType.Bot, bot_token);
    await client.StartAsync();
    result = await WaitForConnected(client, cts.Token);
  }
  catch(Exception ex) {
    Console.ForegroundColor = ConsoleColor.Red;
    Logger.Log($ "Exception {ex.Message}");
    Console.ResetColor();
  }

  return result;
}

But errors appear with connecting to the server when sending in parallel to more than 2 servers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...