質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

.NET Framework

.NET Framework は、Microsoft Windowsのオペレーティングシステムのために開発されたソフトウェア開発環境/実行環境です。多くのプログラミング言語をサポートしています。

Q&A

解決済

1回答

1070閲覧

C#でBOTを作る方法

kakka

総合スコア11

Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

.NET Framework

.NET Framework は、Microsoft Windowsのオペレーティングシステムのために開発されたソフトウェア開発環境/実行環境です。多くのプログラミング言語をサポートしています。

0グッド

0クリップ

投稿2020/02/11 09:44

編集2020/02/11 09:48

C#でBOTを作りたくこちらのサイトを拝見して試しにつくってみたのですがうまく動いてませんなんとか動かしたいです
Program.cs

C#

1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Threading.Tasks; 6using Discord.Commands; 7using Discord.WebSocket; 8using Microsoft.Extensions.DependencyInjection; 9using System.Reflection; 10using Discord; 11namespace bot 12{ 13 class Program 14 { 15 public static DiscordSocketClient client; 16 public static CommandService commands; 17 public static IServiceProvider services; 18 static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult(); 19 public async Task MainAsync() 20 { 21 client = new DiscordSocketClient(); 22 commands = new CommandService(); 23 services = new ServiceCollection().BuildServiceProvider(); 24 client.MessageReceived += CommandRecieved; 25 client.Log += Log; 26 string token = "NjczNDM2MTM0ODYwMTI4MjU2.XkJpYQ.ZkczJ6aqjBthTiintQS4DfQoRt8"; 27 await commands.AddModulesAsync(Assembly.GetEntryAssembly(),services); 28 await client.LoginAsync(TokenType.Bot, token); 29 await client.StartAsync(); 30 await Task.Delay(-1); 31 } 32 /// <summary> 33 /// </summary> 34 /// <param name="msgParam"></param> 35 /// <returns></returns> 36 private async Task CommandRecieved(SocketMessage messageParam) 37 { 38 var message = messageParam as SocketUserMessage; 39 Console.WriteLine("{0} {1}:{2}", message.Channel.Name, message.Author.Username, message); 40 if (message == null) { return; } 41 if (message.Author.IsBot) { return; } 42 int argPos = 0; 43 if (!(message.HasCharPrefix('.', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) { return; } 44 var context = new CommandContext(client, message); 45 var result = await commands.ExecuteAsync(context, argPos, services); 46 if (!result.IsSuccess) { await context.Channel.SendMessageAsync(result.ErrorReason); } 47 } 48 /// <summary> 49 /// コンソール表示処理 50 /// </summary> 51 /// <param name="msg"></param> 52 /// <returns></returns> 53 private Task Log(LogMessage msg) 54 { 55 Console.WriteLine(msg.ToString()); 56 return Task.CompletedTask; 57 } 58 } 59}

Messages.cs

C#

1using Discord.Commands; 2using System; 3using System.Collections.Generic; 4using System.Linq; 5using System.Text; 6using System.Threading.Tasks; 7namespace bot 8{ 9 public class Messages : ModuleBase 10 { 11 private readonly Dictionary<int, string> rule = new Dictionary<int, string>() 12 { 13 {0, "ナワバリ"}, 14 {1, "エリア"}, 15 {2, "ホコ"}, 16 {3, "ヤグラ"}, 17 {4, "アサリ"}, 18 }; 19 private readonly Dictionary<int, string> stage = new Dictionary<int, string>() 20 { 21 {0, "バッテラストリート" }, 22 {1 , "フジツボスポーツクラブ"}, 23 {2 , "ガンガゼ野外音楽堂"}, 24 {3 , "チョウザメ造船"}, 25 {4 , "海女美術大学"}, 26 {5 , "コンブトラック"}, 27 {6 , "マンタマリア号"}, 28 {7 , "ホッケふ頭"}, 29 {8 , "タチウオパーキング"}, 30 {9 , "エンガワ河川敷"}, 31 {10, "モズク農園"}, 32 {11, "Bバスパーク"}, 33 {12, "デボン海洋博物館"}, 34 {13, "ザトウマーケット"}, 35 {14, "ハコフグ倉庫"}, 36 {15, "アロワナモール"} 37 }; 38 [Command("Rl")] 39 public async Task Rl() 40 { 41 Random random = new Random(); 42 int randomRule = random.Next(5); 43 int randomStage = random.Next(16); 44 string Messages = "次の試合のルールは、\n ・**" + rule[randomRule].ToString() + "**\n\n" + "次の試合のステージは、\n ・**" + stage[randomStage].ToString() + "**\n"; 45 await ReplyAsync(Messages); 46 } 47 } 48}

エラー

今のところない

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

単純にSystem.Drawing参照してませんでした

投稿2020/02/11 09:50

編集2020/02/13 08:03
kakka

総合スコア11

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2020/02/12 01:25

回答欄に書いて「解決した方法」マークを付けるなら、どのように解決したのかもう少し詳しく(例えば、何が理解できたから解決できたのかなど)を書いていただけませんか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問