【发布时间】:2020-10-10 14:49:10
【问题描述】:
所以,我试图制作一个 DM 命令,询问我们要将 DM 消息(值)发送给哪个用户,例如 - !vx dm THIS IS THE CONTENT OF THE MESSAGE 将向消息的作者发送一条消息,询问 - “”谁你要dm吗到 X"。这就是我想要的命令。
@client.command()
async def dm(ctx, value):
member = discord.Member if not discord.Member else discord.Member
await ctx.send(f"{ctx.author.mention}, Whom do you want to send the message to?")
def check(m):
return m.content == member.mention == member
await ctx.member.send(f"**{value}**")
await ctx.member.send(f"||Sent by {ctx.author.mention} via VX Helper.||")
e = discord.Embed(title=f"Message sent to {member.display_name}.", description=f"Message Content - {value}.", colour=0x40cc88)
e.set_footer(text=f"Sent by {ctx.author.display_name}", icon_url=ctx.author.avatar_url)
await ctx.channel.purge(limit=3)
await ctx.send(embed=e)
这段代码在heroku中打印出这个错误-
2020-06-20T12:03:12.632899+00:00 app[worker.1]: Ignoring exception in command dm:
2020-06-20T12:03:12.635752+00:00 app[worker.1]: Traceback (most recent call last):
2020-06-20T12:03:12.635825+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/discord/ext/commands/core.py", line 85, in wrapped
2020-06-20T12:03:12.635826+00:00 app[worker.1]: ret = await coro(*args, **kwargs)
2020-06-20T12:03:12.635861+00:00 app[worker.1]: File "run.py", line 336, in dm
2020-06-20T12:03:12.635862+00:00 app[worker.1]: await ctx.member.send(f"**{value}**")
2020-06-20T12:03:12.635920+00:00 app[worker.1]: AttributeError: 'Context' object has no attribute 'member'
2020-06-20T12:03:12.635960+00:00 app[worker.1]:
2020-06-20T12:03:12.635963+00:00 app[worker.1]: The above exception was the direct cause of the following exception:
2020-06-20T12:03:12.635963+00:00 app[worker.1]:
2020-06-20T12:03:12.635999+00:00 app[worker.1]: Traceback (most recent call last):
2020-06-20T12:03:12.636064+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 892, in invoke
2020-06-20T12:03:12.636065+00:00 app[worker.1]: await ctx.command.invoke(ctx)
2020-06-20T12:03:12.636097+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/discord/ext/commands/core.py", line 824, in invoke
2020-06-20T12:03:12.636098+00:00 app[worker.1]: await injected(*ctx.args, **ctx.kwargs)
2020-06-20T12:03:12.636131+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/discord/ext/commands/core.py", line 94, in wrapped
2020-06-20T12:03:12.636132+00:00 app[worker.1]: raise CommandInvokeError(exc) from exc
2020-06-20T12:03:12.636184+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'member'
任何帮助将不胜感激!
【问题讨论】:
-
ctx.author不是ctx.member。我强烈建议查看文档 -
这个
discord.Member if not discord.Member else discord.Member也没有意义。 -
我不想将消息发送给作者,我希望将其发送给他提到的用户。
标签: python python-3.x discord discord.py-rewrite