0
我正在制作一个不和谐的机器人,对c#编码几乎没有任何经验。我得到了一个基本的命令结构,但我无法实现一个无限循环定时器,它将每小时运行一次命令到代码中。我已经得到足够的地方,在命令的工作和随机我只是不能得到小时计时器。任何帮助是极大的赞赏。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);
}
}
}