回答編集履歴

3

コードの修正。

2018/07/16 12:13

投稿

Lazialize
Lazialize

スコア58

answer CHANGED
@@ -1,3 +1,31 @@
1
+ ```python
2
+ voice = None
3
+ player = None
4
+ @client.event
5
+ async def on_message(message):
6
+ global voice, player
7
+ if message.author.bot:
8
+ return
9
+ if message.author.voice_channel is None:
10
+ await client.send_message(message.channel ,'ボイスチャンネルに参加した上で、もう一度実行してください。')
11
+ return
12
+ if voice == None:
13
+ voice = await client.join_voice_channel(message.author.voice_channel)
14
+ # 接続しているかを確認
15
+ elif(voice.is_connected() == True):
16
+ # 接続先で音声を流しているか確認
17
+ if(player.is_playing()):
18
+ # 流していれば停止させる
19
+ player.stop()
20
+ await voice.move_to(message.author.voice_channel)
21
+ player = await voice.create_ytdl_player('https://www.youtube.com/watch?v=ZiAOvG82xN4')
22
+ player.start()
23
+ ```
24
+
25
+ これでどうでしょうか。
26
+
27
+ ---
28
+
1
29
  send_message()は基本的に以下のようにして使います。
2
30
  ```python
3
31
  await client.send_message(メッセージを送信するチャンネル, '送信するメッセージ')

2

編集のミス。

2018/07/16 12:13

投稿

Lazialize
Lazialize

スコア58

answer CHANGED
@@ -26,7 +26,9 @@
26
26
  player.start()
27
27
  ```
28
28
  動かしてはいないので、間違っているかもしれません。
29
+
29
30
  ---
31
+
30
32
  いくつか間違いがあるので訂正をさせていただきますね。
31
33
 
32
34
  まず、肝心の動かなくなる原因ですが、一度コマンドを実行した際にボイスチャンネルにボットが参加すると思います。

1

質問への回答

2018/07/16 10:25

投稿

Lazialize
Lazialize

スコア58

answer CHANGED
@@ -1,3 +1,32 @@
1
+ send_message()は基本的に以下のようにして使います。
2
+ ```python
3
+ await client.send_message(メッセージを送信するチャンネル, '送信するメッセージ')
4
+ ```
5
+ 次に接続の確認ですが以下のような実装になるかと思います。
6
+ ```python
7
+ voice = None
8
+ player = None
9
+ @client.event
10
+ async def on_message(message):
11
+ if message.author.bot:
12
+ return
13
+ if message.author.voice_channel is None:
14
+ await client.send_message(message.channel ,'ボイスチャンネルに参加した上で、もう一度実行してください。')
15
+ return
16
+ if voice == None:
17
+ voice = await client.join_voice_channel(message.author.voice_channel)
18
+ # 接続しているかを確認
19
+ elif(voice.is_connected() == True):
20
+ # 接続先で音声を流しているか確認
21
+ if(player.is_playing()):
22
+ # 流していれば停止させる
23
+ player.stop()
24
+ await voice.move_to(message.author.voice_channel)
25
+ player = await voice.create_ytdl_player('https://www.youtube.com/watch?v=ZiAOvG82xN4')
26
+ player.start()
27
+ ```
28
+ 動かしてはいないので、間違っているかもしれません。
29
+ ---
1
30
  いくつか間違いがあるので訂正をさせていただきますね。
2
31
 
3
32
  まず、肝心の動かなくなる原因ですが、一度コマンドを実行した際にボイスチャンネルにボットが参加すると思います。