python - 缺少 1 个必需的位置参数:“ctx”
问题描述
我试图让我的机器人在用户对消息做出反应后赋予角色,但每次我得到同样的错误。我不明白错误是什么意思。有人可以帮忙吗?这是代码:
import discord
from discord.ext import commands
from discord import Member
from discord.ext.commands import has_permissions
from discord.ext import tasks
#sets the command prefix
Client = commands.Bot(command_prefix = "!")
#print Nuggie is ready in the console when the bot is activeted
@Client.event
async def on_ready():
print("Bot is ready")
@Client.event
async def on_ready(ctx):
myRole = Role.id("Member")
channel = discord.utils.get(ctx.guild.channels, name=input("What is the name of the channel? "))
channel_id = channel.id
channel = Client.get_channel(channel_id)
role = discord.utils.get(message.server.roles, name=myRole)
message = await Client.send_message(channel, "React with the tick to get access to the server!")
while True:
reaction = await Client.wait_for_reaction(emoji="✔", message=message)
await Client.add_roles(reaction.message.author, role)
我得到的错误是:
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
TypeError: on_ready() missing 1 required positional argument: 'ctx'
解决方案
函数 on_ready 定义了两次,当第二个定义时,第一个被消除。该错误告诉您函数调用需要将参数传递给它(ctx)
阅读不和谐文档:https ://discordpy.readthedocs.io/en/latest/quickstart.html#a-minimal-bot 。on_ready 方法必须在没有任何参数的情况下定义。
推荐阅读
- python - 如何为可变大小的图像配置 tf.data.Dataset?
- python - Pandas 均值函数返回所有 NaN
- java - 以前使用 data.sql 导入数据时无法使用 save() 插入
- android - org.mockito.exceptions.verification.NoInteractionsWanted:单元测试失败 - MVI 架构
- github - 如何将用户添加到 GitHub 并生成令牌?
- ag-grid - 如何在 Ag-Grid 中将相同的相邻行与动态行跨度合并?
- java - 如何在数据框中动态地从列表中选择列以及固定列
- python - 表示从有限集到有限集的函数集
- r - 如何对 data.frame 中不同级别的因子应用相同的函数
- plotly - 如何在绘图中修改 Y 轴刻度以适应具有不同范围的图形?