discord.py - 在 disocrd.py 中我的 automod 系统有问题
问题描述
因此,我正在尝试制作一个事件,如果有人发送任何邀请链接,我的 BOT 将检测、删除它并将用户静音,并在我的日志频道中发送日志告诉用户尝试发送邀请链接到目前为止,这是我的代码:
@bot.event
async def on_message(ctx, message):
discordInviteFilter = re.compile("(...)?(?:https?://)?discord(?:(?:app)?\.com/invite|\.gg)/?[a-zA-Z0-9]+/?")
guild = ctx.guild
embed1=discord.Embed(title="Muted successfully", colour=red)
embed1.set_thumbnail(url=message.member.avatar_url)
embed1.add_field(name="Reason", value=f"Send invite link", inline=False)
mutedRole = discord.utils.get(guild.roles, name=" | Muted")
channel = discord.utils.get(message.member.guild.channels, name="║logs")
if discordInviteFilter.match(message.content):
await ctx.message.delete()
await ctx.message.channel.send(f'{ctx.message.author.mention}, invite link are not allowed here. Please read the rules again')
await bot.process_commands(message)
await ctx.message.author.add_roles(mutedRole)
await channel.send(embed=embed1)
当我运行我的代码并发送邀请链接时,这就是我遇到的错误
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Blue\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
TypeError: on_message() missing 1 required positional argument: 'message'
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Blue\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
TypeError: on_message() missing 1 required positional argument: 'message'
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Blue\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
TypeError: on_message() missing 1 required positional argument: 'message'
这些行有什么错误吗?我需要你的帮助。非常感谢
解决方案
您正在为on_message
event 提供 2 个参数,它只需要一个参数,即message
.
删除ctx
参数并尝试以下代码:
@bot.event
async def on_message(message):
discordInviteFilter = re.compile("(...)?(?:https?://)?discord(?:(?:app)?\.com/invite|\.gg)/?[a-zA-Z0-9]+/?")
guild = message.guild
embed1=discord.Embed(title="Muted successfully")
embed1.set_thumbnail(url=message.author.avatar_url)
embed1.add_field(name="Reason", value=f"Send invite link", inline=False)
mutedRole = discord.utils.get(guild.roles, name=" | Muted")
channel = discord.utils.get(message.author.guild.channels, name="║logs")
if discordInviteFilter.match(message.content):
await message.delete()
await message.channel.send(f'{message.author.mention}, invite link are not allowed here. Please read the rules again')
await bot.process_commands(message)
await message.author.add_roles(mutedRole)
await channel.send(embed=embed1)
推荐阅读
- python - 从 DataFrame 创建字典
- hashicorp-vault - hashcorp vault - 无法使用 API 列出机密,但可以使用 CLI 成功验证
- kendo-ui - Kendo DropDownTree 过滤器不显示节点子级
- python - 如何规范化词嵌入(word2vec)
- r - 从单个数据集中渲染多个图(闪亮)
- reactjs - 没有 `type="submit"` 的提交按钮如何工作
- json - if-then 在 kotlin 的 @JsonProperty 中?
- angular - 重定向所有带前缀的路由
- asp.net - 如何在使用 ASP.NET Core 上传文件之前验证请求
- amazon-web-services - 使用 AWS Cognito 授权客户端应用程序和用户