我需要帮助在 discord py 中创建 discord py temp 静音命令

时间:2023-05-11
本文介绍了我需要帮助在 discord py 中创建 discord py temp 静音命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

I got my discord bot to have a mute command but you have to unmute the user yourself at a later time, I want to have another command called "tempmute" that mutes a member for a certain number of minutes/hours/ or days, this is my code so far, how would I make a temp mute command out of this?

#mute command 
@client.command()
@commands.has_permissions(kick_members=True)
async def mute(ctx, member: discord.Member=None):
    if not member:
        await ctx.send("Who do you want me to mute?")
        return
    role = discord.utils.get(ctx.guild.roles, name="muted")
    await member.add_roles(role)
    await ctx.send("ok I did it")

解决方案

Similar to how you gave them a role to mute them, just add another parameter to take in how long you want them to be muted in seconds. Then you can use await asyncio.sleep(mute_time) before removing that role.

The code will look something like:

import asyncio

#mute command 
@client.command()
@commands.has_permissions(kick_members=True)
async def mute(ctx, member: discord.Member=None, mute_time : int):
    if not member:
        await ctx.send("Who do you want me to mute?")
        return
    role = discord.utils.get(ctx.guild.roles, name="muted")
    await member.add_roles(role)
    await ctx.send("ok I did it")

    await asyncio.sleep(mute_time)
    await member.remove_roles(role)
    await ctx.send("ok times up")

这篇关于我需要帮助在 discord py 中创建 discord py temp 静音命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:ModuleNotFoundError:没有名为“不和谐"的模块 下一篇:传递了不正确的令牌

相关文章