我需要在Discord py中制作Discord py temp Mutute命令的帮助

时间:2020-03-28 16:06:49

标签: python discord discord.py

我让我的discord机器人有一个静音命令,但是您必须稍后自己取消静音,我想使用另一个名为“ tempmute”的命令将某个成员静音几分钟/小时/或者天,到目前为止,这是我的代码,如何从中发出一个临时静音命令?

#include <iostream>
#include <string>
#include <vector>

class Book final
{
public:
    // constructor with initializer list
    Book( std::string name_, std::string author_ ) : name{name_}, author{author_} {}

    // accessor methods
    std::string getName() const { return name; }
    std::string getAuthor() const { return author; }

private:
    std::string name;
    std::string author;
};

int main()
{
    std::vector<Book> books;

    books.push_back( Book{"The Alchemist", "Paulo Coehlo"} );
    books.push_back( Book{"Fight Club", "Chuck Palahniuk"} );
    books.push_back( Book{"No Country for Old Men", "Cormac McCarthy"} );

    books.emplace_back( "Brave New World", "Aldous Huxley" );
    books.emplace_back( "1984", "George Orwell" );
    books.emplace_back( "Animal Farm", "George Orwell" );

    for ( const auto& book : books )
    {
        std::cout << book.getName() << " by " << book.getAuthor() << '\n';
    }

    return 0;
}

2 个答案:

答案 0 :(得分:4)

类似于您赋予他们角色使其静音的方式,只需添加另一个参数即可使您希望在几秒钟内将其静音。然后,您可以在删除该角色之前使用await asyncio.sleep(mute_time)。

代码如下:

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")

答案 1 :(得分:0)

import asyncio

@commands.command()
@commands.has_permissions(manage_messages=True)
async def mute(ctx, member: discord.Member,time):
    muted_role=discord.utils.get(ctx.guild.roles, name="Muted")
    time_convert = {"s":1, "m":60, "h":3600,"d":86400}
    tempmute= int(time[0]) * time_convert[time[-1]]
    await ctx.message.delete()
    await member.add_roles(muted_role)
    embed = discord.Embed(description= f"✅ **{member.display_name}#{member.discriminator} muted successfuly**", color=discord.Color.green())
    await ctx.send(embed=embed, delete_after=5)
    await asyncio.sleep(tempmute)
    await member.remove_roles(muted_role)