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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Q&A

1回答

2792閲覧

[Ruby]DiscordのBotを作成したいのですが、実行時のエラーで困っています。

ku_ro.3

総合スコア8

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

0グッド

0クリップ

投稿2019/01/11 14:52

編集2019/01/11 15:11

プログラム参考元の記事を真似して、DiscordのBotを導入しようとしたのですが、エラーが出てしまいます。

Ruby

1# -*- encoding: utf-8 -*- 2require 'discordrb' 3 4TOKEN = 'NTMyOTAzMDAyMzY1ODg2NDY4.DxjSHg.h2-r0-tDZnqJNn4inIHh1M8XORg' 5CLIENT_ID = 532903002365886468 6 7# 通知用のチャンネルID 8inform_channel = '#call' 9 10# bot 11bot = Discordrb::Commands::CommandBot.new token: TOKEN,client_id: CLIENT_ID,prefix:'/' 12 13# 誰かがvoice channelに出入りしたら発火 14bot.voice_state_update do |event| 15 # 発火させたユーザー名を取得 16 user = event.user.name 17 18 # もしデータが空だと抜けていったチャンネルを取得 19 if event.channel == nil then 20 # チャンネル名を取得 21 channel_name = event.old_channel.name 22 23 # 退出したことをinform_channelに通知 24 bot.send_message(inform_channel, "@everyone #{user}#{channel_name}を出たで~") 25 else 26 # チャンネル名を取得 27 channel_name = event.channel.name 28 29 # 入室したことをinform_channelに通知 30 bot.send_message(inform_channel, "@everyone #{user}#{channel_name}に入ったで~") 31 end 32end 33 34# botを起動 35bot.run

cmd

1ruby calling_bot.rb 2[INFO : websocket @ 2019-01-11 23:43:39.158] Discord using gateway protocol version: 6, requested: 6 3[ERROR : et-1 @ 2019-01-11 23:43:56.729] Exception: #<RestClient::NotFound: 404 Not Found> 4[ERROR : et-1 @ 2019-01-11 23:43:56.730] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/abstract_response.rb:249:in `exception_with_response' 5[ERROR : et-1 @ 2019-01-11 23:43:56.731] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/abstract_response.rb:129:in `return!' 6[ERROR : et-1 @ 2019-01-11 23:43:56.731] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:831:in `process_result' 7[ERROR : et-1 @ 2019-01-11 23:43:56.731] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:738:in `block in transmit' 8[ERROR : et-1 @ 2019-01-11 23:43:56.732] C:/Ruby26-x64/lib/ruby/2.6.0/net/http.rb:920:in `start' 9[ERROR : et-1 @ 2019-01-11 23:43:56.732] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:722:in `transmit' 10[ERROR : et-1 @ 2019-01-11 23:43:56.732] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:158:in `execute' 11[ERROR : et-1 @ 2019-01-11 23:43:56.733] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:58:in `execute' 12[ERROR : et-1 @ 2019-01-11 23:43:56.733] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient.rb:70:in `post' 13[ERROR : et-1 @ 2019-01-11 23:43:56.733] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/api.rb:81:in `raw_request' 14[ERROR : et-1 @ 2019-01-11 23:43:56.734] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/api.rb:112:in `request' 15[ERROR : et-1 @ 2019-01-11 23:43:56.734] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/api/channel.rb:76:in `create_message' 16[ERROR : et-1 @ 2019-01-11 23:43:56.734] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/bot.rb:367:in `send_message' 17[ERROR : et-1 @ 2019-01-11 23:43:56.735] calling_bot.rb:30:in `block in <main>' 18[ERROR : et-1 @ 2019-01-11 23:43:56.735] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/events/generic.rb:98:in `call' 19[ERROR : et-1 @ 2019-01-11 23:43:56.735] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/bot.rb:1316:in `block in call_event' 20[ERROR : et-2 @ 2019-01-11 23:44:01.105] Exception: #<RestClient::NotFound: 404 Not Found> 21[ERROR : et-2 @ 2019-01-11 23:44:01.106] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/abstract_response.rb:249:in `exception_with_response' 22[ERROR : et-2 @ 2019-01-11 23:44:01.108] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/abstract_response.rb:129:in `return!' 23[ERROR : et-2 @ 2019-01-11 23:44:01.110] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:831:in `process_result' 24[ERROR : et-2 @ 2019-01-11 23:44:01.112] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:738:in `block in transmit' 25[ERROR : et-2 @ 2019-01-11 23:44:01.114] C:/Ruby26-x64/lib/ruby/2.6.0/net/http.rb:920:in `start' 26[ERROR : et-2 @ 2019-01-11 23:44:01.118] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:722:in `transmit' 27[ERROR : et-2 @ 2019-01-11 23:44:01.120] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:158:in `execute' 28[ERROR : et-2 @ 2019-01-11 23:44:01.123] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient/request.rb:58:in `execute' 29[ERROR : et-2 @ 2019-01-11 23:44:01.125] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rest-client-2.1.0.rc1/lib/restclient.rb:70:in `post' 30[ERROR : et-2 @ 2019-01-11 23:44:01.130] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/api.rb:81:in `raw_request' 31[ERROR : et-2 @ 2019-01-11 23:44:01.132] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/api.rb:112:in `request' 32[ERROR : et-2 @ 2019-01-11 23:44:01.133] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/api/channel.rb:76:in `create_message' 33[ERROR : et-2 @ 2019-01-11 23:44:01.135] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/bot.rb:367:in `send_message' 34[ERROR : et-2 @ 2019-01-11 23:44:01.140] calling_bot.rb:24:in `block in <main>' 35[ERROR : et-2 @ 2019-01-11 23:44:01.141] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/events/generic.rb:98:in `call' 36[ERROR : et-2 @ 2019-01-11 23:44:01.143] C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/bot.rb:1316:in `block in call_event' 37Traceback (most recent call last): 38 3: from calling_bot.rb:35:in `<main>' 39 2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/bot.rb:243:in `run' 40 1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/gateway.rb:179:in `sync' 41C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/discordrb-3.3.0/lib/discordrb/gateway.rb:179:in `join': Interrupt

参考元と別ページのDiscordのBotに関する記述
ここによると、最初のinfoは出ても問題ないもののようです。

ERROR : et-1は入室した時に出たエラー、
ERROR : et-2は退室した時に出たエラーです。

最後のTracebackから始まる3文がエラー解決のカギなのではないかとは思いますが、分かりません。
どうかよろしくお願いします。

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

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

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

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

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

guest

回答1

0

すいません
初めての回答です
bot.send_message(channel.id,"メッセージです")
channel名ではありません
分かりに久手すいません

投稿2019/08/21 08:10

tatchanrb

総合スコア10

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問