所以,我正在尝试创建一个DM命令,询问我们想要将DM消息(值)发送给哪个用户,ex- !vx dm THIS IS THE CONTENT OF THE MESSAGE会向消息的作者发送一条消息,询问-“”您想要dm给谁?“而作者将通过提及他想要将DM发送给谁的人来回复,在这样做之后,它会将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'任何帮助都将不胜感激!
发布于 2020-06-20 22:15:06
因此,理想情况下,您应该在命令中获取用户输入。这将为您省去使用wait_for的麻烦,尽管您似乎已经尝试过这样做。这是一个简单的方法,您可以使用一些代码向提到的任何人发送消息。
@bot.command()
async def dm(ctx, user: discord.User, *, value):
# Send a message to the mentioned user!
await user.send(f"**{value}**")
await user.send(f"||Sent by {ctx.author.display_name} via VX Helper.||")因此,从本质上讲,这里有几件事需要理解。首先,我们正在解析一个user: discord.User参数,这是我们要发送消息的人。使用: discord.User只是意味着D.py会自动将其转换为有效用户,因此我们可以直接发送到该对象。这里要理解的第二件事是*, value的用法。简单地说,这意味着您提到用户之后出现的任何内容都将被放入value变量的字符串中。您可以阅读有关该here背后的逻辑的更多信息
在此之后,您可以简单地完成您想要的代码。我希望这对你有帮助!
https://stackoverflow.com/questions/62485675
复制相似问题