在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 (我的前缀是!)。控制台中的输出错误:
Context命令引发异常: AttributeError:‘discord.ext.commands.errors.CommandInvokeError:’对象没有属性'content‘
发布于 2021-01-19 22:29:12
为了获得命令的其余消息,您需要传递另一个参数。此参数将包括在!rps之后发送的所有消息。此外,在命令中使用ctx比使用msg更好。
@bot.command()
async def rps(ctx, *, args):
if ctx.channel.id != channel:
return
await ctx.send(args)在此代码中,args参数包括!rps之后的所有消息。
https://stackoverflow.com/questions/65793388
复制相似问题