如果他们说一个特定的单词discord py rewrite,则自动将成员静音

auto mute a member if they say a specific word discord py rewrite

import discord
import re
from itertools import cycle


class Status(commands.Cog):
    def __init__(self, client):
        self.client = client
 @commands.Cog.listener()
    async def on_message(self, ctx):
        if ctx.author.id == self.client.user.id:
            return
        if re.search("\.\.\.", ctx.content):
            await ctx.send("you're... gonna get... muted... if you.. talk... like.. this...")
            user = ctx.message.author
            # print(str(user))
            # print(str(message.content))
            muted_role = discord.utils.get(ctx.author.guild.roles, name="Muted")
            await self.client.add_roles(ctx.author, muted_role)

我想要的是,如果用户在发送的消息中使用省略号,则暂时将其静音。 ctx.send 不起作用,机器人不向频道发送消息。它说 self.client.add_roles 不存在。

Muted是我创建的角色,没有任何发送消息权限。

知道为什么吗?一些帮助将不胜感激。我正在使用

AttributeError: 'Message' object has no attribute 'send' 这是我得到的错误

[编辑]

    @commands.Cog.listener()
    # @commands.command()
    async def on_message(self, message):
        if message.author.id == self.client.user.id:
            return
        if re.search("\.\.\.", message.content):
            await message.channel.send("you're... gonna get... muted... if you.. talk... like.. this...")
            user = message.author
            muted_role = discord.utils.get(message.guild.roles, name="Muted")
            await user.add_roles(muted_role, reason="you know what you did", atomic=True)

我看了下文档,做了这个,成功了,谢谢支持:)

错误较多,请看documentation

我已经帮你更正了 -

 @commands.Cog.listener()
    async def on_message(self, message):
        if message.author.id == self.client.user.id:
            return
        else:
            await message.channel.send("you're... gonna get... muted... if you.. talk... like.. this...")
            user = message.author
            print(str(user))
            print(str(message.content))
            muted_role = discord.utils.get(message.guild.roles, name="Muted")
            await self.user.add_roles(muted_role)

如果您仍然遇到任何错误,请告诉我。

最后编辑-

我在齿轮外为自己尝试了这个命令,它运行得非常好:)

@client.event
async def on_message(message):
    if message.author.id == client.user.id:
        return
    elif "test" in message.content:
        await message.channel.send("you're... gonna get... muted... if you.. talk... like.. this...")
        user = message.author
        print(str(user))
        print(str(message.content))
        muted_role = discord.utils.get(message.guild.roles, name="Muted")
        await user.add_roles(muted_role)
    else:
        return
    await client.process_commands(message)