from discord.ext import commands
from discord.utils import get
client = discord.Client()
ROLE = 'SPECIAL'
BOT_PREFIX = '/'
bot = commands.Bot(command_prefix=BOT_PREFIX)
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message, member):
if message.author == client.user:
return
if message.author.name == "Pawlu_il_Fenku":
await message.channel.send('Hello!')
role = get(member.guild.roles, name=ROLE)
await member.add_roles(role)
print(f"{member} was given {role}")
client.run('NzY0MjA1MzA1MjQwMjIzNzQ0.X4C3pw.5RmXn1XswHCTWwOQ5i1v5lH5B6I')
当我运行它并键入一些内容时,它会给我以下信息:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\jpbay\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
TypeError: on_message() missing 1 required positional argument: 'member'
有什么帮助吗?
答案 0 :(得分:0)
on_message
事件只有1个参数,即message
。在这种情况下,您不能使用2个参数,但是可以使用member
访问message.author
对象具有的每个属性。
此外,我不建议您同时使用discord.Client
和discord.Bot
。 discord.Bot
可以做discord.Client
做的所有事情。
ROLE = 'SPECIAL'
BOT_PREFIX = '/'
client = commands.Bot(command_prefix=BOT_PREFIX)
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message, member):
if message.author == client.user:
return
if message.author.name == "Pawlu_il_Fenku":
await message.channel.send('Hello!')
role = get(message.guild.roles, name=ROLE)
await message.author.add_roles(role)
print(f"{message.author} was given {role}")
client.run('TOKEN')
注意:
如果尚未更改令牌,则应该更改。