簡體   English   中英

為什么靜音命令在 Discord.py 中不起作用?

[英]Why doesn't the mute command not work in Discord.py?

.mute命令由於某種原因不起作用。 有人可以幫我嗎?

我的代碼:

@client.command(pass_context=True)
async def mute(ctx, arg):
    user = client.get_user(int(arg))
    role = get(user.server.roles, name="Muted")
    async with ctx.typing():
        time.sleep(1)
    await ctx.send('Muted: ', '<@', int(arg), '>')
    client.add_roles(user, role)

用這個替換你的mute命令:

@client.command(pass_context=True)
async def mute(ctx, id: int):
    member = await ctx.guild.fetch_member(id)
    role = discord.utils.get(ctx.guild.roles, name = 'Muted')
    async with ctx.typing():
        time.sleep(1)
    await ctx.send(f'Muted: {member.mention}')
    await member.add_roles(role)

注意:我建議將 time.sleep(1 time.sleep(1)替換為await asyncio.sleep(1) 在這種情況下,您必須導入asyncio

暫無
暫無

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

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