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)
我查看了文档并做了这个,它有效,感谢您的支持:)