【发布时间】:2026-01-13 11:00:02
【问题描述】:
在 discord.py 中是否有一些选项我可以在命令下访问 msg.content(或 ctx.content 每个人如何使用它)?下面你可以看到我的意思的两个例子。第一个是事件,我只需复制消息并让机器人将其发回。第二个是命令,但 msg.content 不起作用。我的问题是我不想过多地使用事件并将一切都置于命令之下。
@bot.event
async def on_message(msg):
chat = bot.get_channel(797224597443051611)
if msg.channel.id != channel:
return
if msg.content.startswith("!rps"):
message = str(msg.content)
await chat.send(message)
有人输入 !rps hello。不和谐的输出是 !rps hello
@bot.command()
async def rps(msg):
if msg.channel.id != channel:
return
message = str(msg.content)
await msg.send(message)
有人输入 !rps hello(我的前缀是 !)。控制台输出错误:
discord.ext.commands.errors.CommandInvokeError: 命令引发异常:AttributeError: 'Context' object has no attribute 'content'
【问题讨论】:
标签: python pycharm discord.py