擅长:python、mysql、java
<p>将代码读作:</p>
<pre class="lang-py prettyprint-override"><code>phrase = 'summon_bot'
import random
char1 = ["character1", "character2", "character3"]
if phrase in comment.body:
random_choice = random.choice(char1)
#random_choice is now a stored variable. Fixed, is the same each time you use it
reply = comment.body.replace(phrase,str(random_choice)) #replaces all occurences of phrase with fixed random_choice
</code></pre>
<p>您需要一种方法来计算每个事件的<code>random.choice(char1)</code>。
例如:</p>
<pre><code>reply = comment.body
while phrase in reply:
random_choice = random.choice(char1)
reply.replace(phrase, random_choice, 1) #extra argument to only replace first occurence
</code></pre>