为了账号安全,请及时绑定邮箱和手机立即绑定

尝试在用户说出某些内容时添加警告角色

尝试在用户说出某些内容时添加警告角色

牧羊人nacy 2023-08-08 16:53:04
Discord 试图message.author在使用await message.author.add_roles(message.author,role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))删除第二个message.author修复此问题时添加角色,因此应该是:await message.author.add_roles(role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))属性错误:Traceback (most recent call last):  File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 312, in _run_event    await coro(*args, **kwargs)  File "C:\Users\Me\Desktop\Productive\Programming Projects\Python 3\Other\MyBot\bot.py", line 41, in on_message    await bot.add_roles(message.author,role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))AttributeError: 'Client' object has no attribute 'add_roles'名称错误:Ignoring exception in on_messageTraceback (most recent call last):  File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 312, in _run_event    await coro(*args, **kwargs)  File "C:\Users\Me\Desktop\Productive\Programming Projects\Python 3\Other\MyBot\bot.py", line 41, in on_message    await add_roles(message.author,role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))NameError: name 'add_roles' is not defined所有相关代码import discord;from discord.utils import getfrom datetime import datetimebot=discord.Client()@bot.eventasync def on_ready():    print('Logged in')    print('Username: %s' % (bot.user.name))    print('Userid: %s' % (bot.user.id))
查看完整描述

2 回答

?
月关宝盒

TA贡献1772条经验 获得超5个赞

on_message中的Message对象应包含 message.author 中的 Member 对象,因此您可以执行以下操作:

await message.author.add_roles(role, reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))


查看完整回答
反对 回复 2023-08-08
?
陪伴而非守候

TA贡献1757条经验 获得超8个赞

过去,我是通过调用消息来完成此操作add_rolesauthor。在你的情况下,它会是这样的:

await message.author.add_roles(role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time)

我认为我没有包含一个reason论点,所以我不确定这种形式是否会采用该论点,但如果其他形式这样做,我认为会的。


查看完整回答
反对 回复 2023-08-08
  • 2 回答
  • 0 关注
  • 128 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信