如何禁止作者在网上留言?

2024-04-25 00:25:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让我的机器人禁止发送消息“$pull”的人,如果他们在randint(1,6)中得到1。你知道吗

        chamber = randint(1,6)
        if chamber == 1:
            await message.channel.send("%s got hoodbridged" % message.author)
            game_active = False

这是我所拥有的,但我也试图让它禁止的人,如果商会==1。谢谢!你知道吗


Tags: sendgame消息messageifchannel机器人await
1条回答
网友
1楼 · 发布于 2024-04-25 00:25:45

我相信你要找的是成员.ban(). 你可以阅读更多关于它in the docs here

要在消息上使用:

@client.event
async def on_message(message):
    if message.content.startswith('$pull'):
        chamber = randint(1,6)
        if chamber == 1:
            await message.channel.send("%s got hoodbridged" % message.author)
            await message.author.ban()

如果你用discord.commands.Bot不一致类的命令用法,则它将如下所示:

prefix = "$"
client = commands.Bot(command_prefix=prefix)

@client.command(pass_context=True)
async def pull(ctx):
    chamber = randint(1,6)
    if chamber == 1:
        await ctx.channel.send("%s got hoodbridged" % ctx.author)
        await ctx.author.ban()

相关问题 更多 >