简体   繁体   English

类型错误:on_message() 缺少 1 个必需的位置参数:“成员”discord.py

[英]TypeError: on_message() missing 1 required positional argument: 'Member' discord.py

I am having a problem with the report command I am working on.我正在处理的报告命令有问题。 Whenever I run the command on my discord server, the error "TypeError: on_message() missing 1 required positional argument: 'Member'" comes up.每当我在 discord 服务器上运行命令时,都会出现错误“TypeError: on_message() missing 1 required positional argument: 'Member'”。 If anyone knows how to solve this problem can you tell me?如果有人知道如何解决这个问题,你能告诉我吗? Thank you for taking your time to read this.感谢您花时间阅读本文。

# bot.py
from discord import Member
import os
import discord
from dotenv import load_dotenv
load_dotenv()
DISCORD_TOKEN = ''

client = discord.Client()

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

@client.event
async def on_message(message, Member):

    Member = discord.Member(Member)

    if message.author == client.user:
        return

    if message.content.startswith('$report ', Member.mention):
        Sends = 'That user has been reported!'
        await message.channel.send(Sends)

client.run(DISCORD_TOKEN)

I can see that your new to discord.py.我可以看到您是 discord.py 的新手。 First of all, the on_message function does not take member.首先,on_message function 不带成员。 It only takes message.它只需要消息。 When you add an event to your code you always want to check the Event Reference and check the paramters for that event.当您将事件添加到代码中时,您总是希望检查事件参考并检查该事件的参数。 You cannot add or remove paramaters.您不能添加或删除参数。 For this case your code would start like this对于这种情况,您的代码将像这样开始

@client.event
async def on_message(message)

To get the member you would use:要获取您将使用的成员:

member = message.author

Also I recommend you use commands另外我建议您使用命令

from discord.ext import commands

It will be a lot easier and you can add your own paramaters.这会容易得多,您可以添加自己的参数。 I've made an example of what you're doing with your on_message function in a command我已经在命令中举例说明了您对 on_message function 所做的事情

@client.command
async def report(ctx, member : discord.Member, reason=None)
    await ctx.send(f"Reported {member.mention} for {reason}")

Also remember if you have an on_message function your commands wont work unless you use bot.process_commands at the end.还要记住,如果你有一个 on_message function,除非你最后使用 bot.process_commands,否则你的命令将不起作用。 Read the FAQ on how to do that.阅读有关如何执行此操作的常见问题解答。 Heres the link: Why does on_message make my commands stop working?这是链接:为什么 on_message 使我的命令停止工作? https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Discord.py 类型错误:on_message() 缺少 1 个必需的仅关键字参数:“搜索” - Discord.py TypeError: on_message() missing 1 required keyword-only argument: 'search' Discord.py on_message() 缺少参数 - Discord.py on_message() missing argument discord.py 类型错误:on_member_join() 缺少 1 个必需的位置参数:“成员”错误 - discord.py TypeError: on_member_join() missing 1 required positional argument: 'member' error discord.py on_message_delete 类型错误:on_message_delete() 缺少 1 个必需的位置参数:'message' - discord.py on_message_delete TypeError: on_message_delete() missing 1 required positional argument: 'message' 类型错误:1 个必需的位置参数,Discord.py - TypeError : 1 required positional argument, Discord.py 类型错误:on_message() 缺少 1 个必需的位置参数:“消息” - TypeError: on_message() missing 1 required positional argument: 'message' 类型错误。 on_message() 缺少 1 个必需的位置参数:'ctx' - TypeError. on_message() missing 1 required positional argument: 'ctx' (discord.py)TypeError:to_components()缺少1个必需的位置参数:'self' - (discord.py) TypeError: to_components() missing 1 required positional argument: 'self' TypeError: on_ready() missing 1 required positional argument: 'self' discord.py - TypeError: on_ready() missing 1 required positional argument: 'self' discord.py 类型错误:__init__() 缺少 1 个必需的位置参数:“字段”(discord.py,嵌入) - TypeError: __init__() missing 1 required positional argument: 'field' (discord.py, embed)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM