【发布时间】:2021-07-28 04:15:38
【问题描述】:
我目前正在处理一个项目,我希望它每隔几秒钟将我的变量 x 更改为与列表不同的值。我已经设置了列表和随机命令,但是现在每次我启动代码时,它都会从列表中选择 1 个选项并保留它直到我停止代码。如何让它继续随机选择,即使在第一个初始选择之后,每隔几秒钟?
from discord.ext import commands
from discord import FFmpegPCMAudio
import random
Audio=['AUDIO_1.mp3','AUDIO_2.mp3','AUDIO_3.mp3']
x=random.choice(Audio)
client = commands.Bot(command_prefix = '!')
@client.event
async def on_ready():
print("The bot is now ready for use.")
print(".............................")
@client.command(pass_context=True)
async def join(ctx):
if (ctx.author.voice):
channel = ctx.message.author.voice.channel
voice = await channel.connect()
source = FFmpegPCMAudio(x)
player = voice.play(source)
else:
await ctx.send("User not in a voice channel, unable to connect.")
@client.command(pass_context=True)
async def leave(ctx):
if (ctx.voice_client):
await ctx.guild.voice_client.disconnect()
await ctx.send("I have left the voice channel.")
else:
await ctx.send("I am not in a voice channel.")
client.run('TOKEN')```
【问题讨论】:
标签: python discord discord.py