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

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_message

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 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 get

from datetime import datetime

bot=discord.Client()


@bot.event

async def on_ready():

    print('Logged in')

    print('Username: %s' % (bot.user.name))

    print('Userid: %s' % (bot.user.id))


牧羊人nacy
浏览 130回答 2
2回答

月关宝盒

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))

陪伴而非守候

过去,我是通过调用消息来完成此操作add_roles的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)我认为我没有包含一个reason论点,所以我不确定这种形式是否会采用该论点,但如果其他形式这样做,我认为会的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python