Discordボットの作成を開始しましたが、すでに問題が発生しています。私はかなりちょうどheがプログラムにあまり影響を及ぼしてはならないマイナーな変更を書いたものを書きました。私は2クラスを持って、ちょうどそのボットのためのトークンを取得し、メインクラスはここDiscord Bot [C#]がコマンドを実行しません
MyBot bot = MyBot(token)
でボットを作成しMyBot.csである:それは接続しない
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
namespace Coding_Bot
{
class MyBot
{
DiscordClient discord;
String botToken;
public MyBot(String tempToken)
{
botToken = tempToken;
discord = new DiscordClient(x =>
{
x.LogLevel = LogSeverity.Info;
x.LogHandler = Log;
});
Console.WriteLine("[BOT] Connecting...");
discord.ExecuteAndWait(async() =>
{
await discord.Connect(botToken, TokenType.Bot);
});
discord.UsingCommands(x =>
{
x.PrefixChar = '.';
x.AllowMentionPrefix = true;
});
var commands = discord.GetService<CommandService>();
commands.CreateCommand("info").Do(async (e) =>
{
Console.WriteLine("!info executed");
await e.Channel.SendMessage("Coding Bot");
});
}
private void Log(object sender, LogMessageEventArgs e)
{
Console.WriteLine("[BOT] " + e.Message);
}
}
}
とボットはありませんオンラインになる。これは私のコンソールの出力です:
[BOT] Connecting...
[BOT] Connected
[BOT] GUILD_AVAILABLE: BotTestServer
私は今、一般的には.infoと入力しても何も起こりません。コンソールには何も表示されず、#generalには何も表示されません。 私は既にthisを見ましたが、私の問題は解決しませんでした。
EDIT:私はCommandHandlerクラスを使用し、すべてのコマンドをそこに置くべきではないことを知っています。私は将来それをしませんが、これはテストのためのものです。
ありがとうございました! MyBot bot = [新規] myBot(トークン); stackoverflowのちょうどタイプミスでした。接続する前にコマンドを置くと、私のために固定されました!ありがとうございました! – FritzFurtz
NuGet Packet ManagerでDiscord.NET v1が見つかりません。 – FritzFurtz
@FritzFurtzプレリリース版をダウンロードするには、新しいパッケージソースが必要です。パッケージのソースは「https://www.myget.org/F/discord-net/api/v3/index.json」です。リリース前のAPIパッケージを使用すると、パッケージのv1を確認できます。ドキュメントはまだリリースされていませんが、私がリンクしたチャットのヘルプを見たり、サンプルボットを使用したりすることができます:https://github.com/420foxbot/DiscordExampleBot – WQYeo