Je suis en train de créer un bot pour les discordances et j'ai peu ou pas d'expérience avec le codage C#. J'ai une structure de base pour les commandes de base mais je ne peux pas implémenter une minuterie en boucle infinie qui va exécuter la commande une fois par heure dans le code. Je suis allé assez loin où la commande fonctionne et est aléatoire, je ne peux pas obtenir le minuteur horaire. Toute aide est grandement appréciée.Commande automatique horaire pour Discord
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bleachedbot
{
class MyBot
{
DiscordClient discord;
CommandService commands;
Random rand;
string[] bestBleach;
public MyBot()
{
rand = new Random();
bestBleach = new string[]
{
//All images in the folder.
"imagetests/Bleach 001.jpg",
"imagetests/Bleach 002.jpg",
"imagetests/Bleach 003.jpg"
};
discord = new DiscordClient(x =>
{
x.LogLevel = LogSeverity.Info;
x.LogHandler = Log;
});
discord.UsingCommands(x =>
{
x.PrefixChar = '-';
x.AllowMentionPrefix = true;
});
commands = discord.GetService<CommandService>();
commands.CreateCommand("help")
.Do(async (e) =>
{
await e.Channel.SendMessage("Commands: ");
});
RegiseterAutoBleachCommand();
discord.ExecuteAndWait(async() =>
{
await discord.Connect("<TOKEN>", TokenType.Bot);
});
}
private void RegiseterAutoBleachCommand()
{
commands.CreateCommand("foldertest")
.Do(async (e) =>
{
int randomHentaiIndex = rand.Next(bestBleach.Length);
string bleachToPost = bestBleach[randomBleachIndex];
await e.Channel.SendFile(bleachToPost);
});
}
private void Log(object sender, LogMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
}
}