回答編集履歴

3

追記

2021/04/14 07:47

投稿

coolwind0202
coolwind0202

スコア708

test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- (追記)
19
+ ### (追記)
20
20
 
21
21
  ```
22
22
 
@@ -44,7 +44,7 @@
44
44
 
45
45
 
46
46
 
47
- (追記2)
47
+ ###(追記2)
48
48
 
49
49
 
50
50
 
@@ -101,3 +101,109 @@
101
101
 
102
102
 
103
103
  `before.self_deaf is not after.self_deaf`
104
+
105
+
106
+
107
+
108
+
109
+ ###(追記3)
110
+
111
+
112
+
113
+ Pythonでは、同じレベルのブロックの中ではインデントの数は同じにする必要があります。
114
+
115
+ というより、インデントの数によってブロックの深さを表現しています。
116
+
117
+
118
+
119
+ ```py
120
+
121
+ print("ボイスチャンネルで変化がありました")
122
+
123
+
124
+
125
+ if((before.self_mute is not after.self_mute) or (before.voice.self_deaf is not after.voice.self_deaf)):
126
+
127
+ print("ボイスチャンネルでミュート設定の変更がありました")
128
+
129
+ return
130
+
131
+
132
+
133
+ if(before.voice_channel is None):
134
+
135
+ pretime_dict[after.name] = datetime.datetime.now()
136
+
137
+ ```
138
+
139
+
140
+
141
+ インデントの数がどれもバラバラなので、これはエラーになります。
142
+
143
+
144
+
145
+ ブロックというのは、「:」記号以降に記述された一連の処理です。
146
+
147
+
148
+
149
+ ```py
150
+
151
+ # ここは一番浅く
152
+
153
+
154
+
155
+ def f():
156
+
157
+ # 関数宣言には「:」がつくので1段下げる
158
+
159
+ for i in range(5):
160
+
161
+ # for文には「:」がつくので1段下げる
162
+
163
+ ```
164
+
165
+
166
+
167
+ このように、「:」でブロックが発生したら1段下げるように覚えればよいと思います
168
+
169
+ (インデントは半角4個のスペースで表現するのが一般的)
170
+
171
+
172
+
173
+ ゆえに、
174
+
175
+
176
+
177
+ ```py
178
+
179
+ @client.event
180
+
181
+ async def on_voice_state_update(member, before, after):
182
+
183
+ print("ボイスチャンネルで変化がありました")
184
+
185
+
186
+
187
+ if((before.self_mute is not after.self_mute) or (before.voice.self_deaf is not after.voice.self_deaf)):
188
+
189
+ print("ボイスチャンネルでミュート設定の変更がありました")
190
+
191
+ return
192
+
193
+
194
+
195
+ if(before.voice_channel is None):
196
+
197
+ pretime_dict[after.name] = datetime.datetime.now()
198
+
199
+ elif(after.voice_channel is None):
200
+
201
+ duration_time = pretime_dict[before.name] - datetime.datetime.now()
202
+
203
+ duration_time_adjust = int(duration_time.total_seconds()) * -1
204
+
205
+ ```
206
+
207
+
208
+
209
+ このように修正するとよいです。

2

追記

2021/04/14 07:46

投稿

coolwind0202
coolwind0202

スコア708

test CHANGED
@@ -37,3 +37,67 @@
37
37
 
38
38
 
39
39
  `before.voice.self_mute` などvoice属性を参照する部分は `before.self_mute` というように置き換えてみてください。
40
+
41
+
42
+
43
+ ----
44
+
45
+
46
+
47
+ (追記2)
48
+
49
+
50
+
51
+ エラーの読み方を知ったほうがよいですね
52
+
53
+
54
+
55
+ ```
56
+
57
+ AttributeError: '〇〇' object has no attribute '▲▲'
58
+
59
+
60
+
61
+ このエラー文はそのまま 「▲▲」という属性は 〇〇 オブジェクトにはない、ということです
62
+
63
+ ```
64
+
65
+
66
+
67
+ ```
68
+
69
+ AttributeError: 'VoiceState' object has no attribute 'voice'
70
+
71
+ ```
72
+
73
+
74
+
75
+ ゆえにこれは VoiceState オブジェクトは voice 属性を持っていないという意味になります。
76
+
77
+ VoiceState はここでは `before` と `after` の型です
78
+
79
+ どこで voice 属性を参照しているでしょうか?
80
+
81
+
82
+
83
+ ここです:
84
+
85
+
86
+
87
+ ```py
88
+
89
+ if((before.self_mute is not after.self_mute) or (before.voice.self_deaf is not after.voice.self_deaf)):
90
+
91
+ ```
92
+
93
+
94
+
95
+ `before.voice.self_deaf is not after.voice.self_deaf`
96
+
97
+
98
+
99
+ before や after にvoice属性はないことを念頭に置いてください:
100
+
101
+
102
+
103
+ `before.self_deaf is not after.self_deaf`

1

AttirbuteErrorへの追記

2021/04/13 23:36

投稿

coolwind0202
coolwind0202

スコア708

test CHANGED
@@ -13,3 +13,27 @@
13
13
 
14
14
 
15
15
  でどうでしょう。
16
+
17
+
18
+
19
+ (追記)
20
+
21
+ ```
22
+
23
+ AttributeError: 'VoiceState' object has no attribute 'voice'
24
+
25
+ ```
26
+
27
+
28
+
29
+ 参考サイトのコードは投稿日を見る限りかなり古いので参考になりません。
30
+
31
+ 全体的に書き直すことになりそうです。
32
+
33
+
34
+
35
+ この `AttributeError` は、before、afterにはそれぞれVoiceStateオブジェクトが入るのでvoice属性を参照できないために発生します。
36
+
37
+
38
+
39
+ `before.voice.self_mute` などvoice属性を参照する部分は `before.self_mute` というように置き換えてみてください。