回答編集履歴

9

修正

2021/08/14 14:20

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -38,7 +38,7 @@
38
38
 
39
39
  def play(voice_client, queue):
40
40
 
41
- if not queue or voice_client.():
41
+ if not queue or voice_client.is_playing():
42
42
 
43
43
  return
44
44
 

8

is_playing追加

2021/08/14 14:20

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -38,7 +38,7 @@
38
38
 
39
39
  def play(voice_client, queue):
40
40
 
41
- if not queue:
41
+ if not queue or voice_client.():
42
42
 
43
43
  return
44
44
 

7

修正

2021/08/14 14:20

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
  source = queue.popleft()
46
46
 
47
- voice_client.play(source, lambda e:play(voice_client, queue))
47
+ voice_client.play(source, after=lambda e:play(voice_client, queue))
48
48
 
49
49
  ```
50
50
 

6

修正(pop->append)

2021/08/14 14:01

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  queue = queue_dict[guild.id]
30
30
 
31
- queue.push(source)
31
+ queue.append(source)
32
32
 
33
33
  if not voice_client.is_playing():
34
34
 

5

typo

2021/08/14 13:48

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  def enqueue(voice_client, guild, source):
28
28
 
29
- queue = stack_dict[guild.id]
29
+ queue = queue_dict[guild.id]
30
30
 
31
31
  queue.push(source)
32
32
 

4

修正

2021/08/14 13:18

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -38,7 +38,7 @@
38
38
 
39
39
  def play(voice_client, queue):
40
40
 
41
- if not stack:
41
+ if not queue:
42
42
 
43
43
  return
44
44
 

3

修正

2021/08/13 20:49

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -1,10 +1,12 @@
1
1
  VioceClient.playは、引数afterに指定した関数を音声再生後かエラー発生時に実行することができます。
2
+
3
+ なのでキューが空になるまでafterで再帰すればいいです。
2
4
 
3
5
 
4
6
 
5
7
  また、キューはcollections.dequeを使うと良いと思います。
6
8
 
7
- 複数のサーバーで運用される場合、スタックはサーバーごとに持たないと音声が混ざってしまうのでdictなどに格納するといいでしょう。
9
+ 複数のサーバーで運用される場合、キューはサーバーごとに持たないと音声が混ざってしまうのでdictなどに格納するといいでしょう。
8
10
 
9
11
 
10
12
 
@@ -42,7 +44,7 @@
42
44
 
43
45
  source = queue.popleft()
44
46
 
45
- voice_client.play(source, lambda e:play(voice_client, queue)
47
+ voice_client.play(source, lambda e:play(voice_client, queue))
46
48
 
47
49
  ```
48
50
 

2

修正

2021/08/13 20:48

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- また、この場合適しているのはキュー(後ろに入れて後ろから出す)でなくスタック(後ろに入れて前から出す)なので、collections.dequeを使うと良いと思います。
5
+ また、キューはcollections.dequeを使うと良いと思います。
6
6
 
7
7
  複数のサーバーで運用される場合、スタックはサーバーごとに持たないと音声が混ざってしまうのでdictなどに格納するといいでしょう。
8
8
 
@@ -18,31 +18,31 @@
18
18
 
19
19
 
20
20
 
21
- stack_dict = defaultdict(deque)
21
+ queue_dict = defaultdict(deque)
22
22
 
23
23
 
24
24
 
25
- def push(voice_client, guild, source):
25
+ def enqueue(voice_client, guild, source):
26
26
 
27
- stack = stack_dict[guild.id]
27
+ queue = stack_dict[guild.id]
28
28
 
29
- stack.push(source)
29
+ queue.push(source)
30
30
 
31
31
  if not voice_client.is_playing():
32
32
 
33
- play(voice_client, stack)
33
+ play(voice_client, queue)
34
34
 
35
35
 
36
36
 
37
- def play(voice_client, stack):
37
+ def play(voice_client, queue):
38
38
 
39
39
  if not stack:
40
40
 
41
41
  return
42
42
 
43
- source = stack.popleft()
43
+ source = queue.popleft()
44
44
 
45
- voice_client.play(source, lambda e:play(voice_client, stack)
45
+ voice_client.play(source, lambda e:play(voice_client, queue)
46
46
 
47
47
  ```
48
48
 

1

修正

2021/08/13 20:46

投稿

kairi003
kairi003

スコア1330

test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
 
24
24
 
25
- def enqueue(voice_client, guild, source):
25
+ def push(voice_client, guild, source):
26
26
 
27
27
  stack = stack_dict[guild.id]
28
28