如何解决如果成员说出特定单词不和谐py,则自动使成员静音
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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。