spam_id = xxxxxx
@tasks.loop(seconds=0.2)
async def spammer(ctx):
text_channel = client.get_channel(spam_id)
if text_channel != None:
num = random.randint(1,2)
await text_channel.send(num)
intervals = [1.0, 1.1, 1.2, 1.3, 1.4]
await asyncio.sleep(random.choice(intervals))发布于 2022-07-11 18:34:10
将spam_id定义为全局变量,并从不同的函数访问/修改它。
spam_id = xxxxxx
@bot.command()
async def modify_spam_id(ctx, new_id : int):
global spam_id
spam_id = new_id
@tasks.loop(seconds=0.2)
async def spammer(ctx):
global spam_id
text_channel = client.get_channel(spam_id)
if text_channel != None:
num = random.randint(1,2)
await text_channel.send(num)
intervals = [1.0, 1.1, 1.2, 1.3, 1.4]
await asyncio.sleep(random.choice(intervals))https://stackoverflow.com/questions/72942529
复制相似问题