簡體   English   中英

有什么方法可以禁用然后啟用 discord.py 中的 client.event() 嗎?

[英]Is there any way to disable and then enable a client.event() in discord.py?

我的 Discord 機器人代碼中有 client.event()。 我正在嘗試建立一種禁用它的方法,因為我的機器人有時會很煩人。 但是,我只想禁用和啟用事件。 是否可以這樣做,如果可以,它的代碼是什么?

一個好主意是使用齒輪。

在這里使用這段代碼:

注意:您需要命令模塊 - from discord.ext import commands

@client.command()
@commands.has_permissions(administrator=True)
async def load(ctx, extension):
    await ctx.send('Succesfully been enabled!')
    client.load_extension(f'cogs.{extension}')

@client.command()
@commands.has_permissions(administrator=True)
async def unload(ctx, extension):
    await ctx.send('Succesfully been disabled!')
    client.unload_extension(f'cogs.{extension}')

您將能夠加載和卸載文件。 因此,將事件放入齒輪中,然后隨時卸載/加載它!

如果你還沒有,我建議你學習齒輪

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM