简体   繁体   English

有人能告诉我我在这里做错了什么 discord.py dming 系统

[英]Can someone tell me what i did wrong here discord.py dming system

I was was trying to get it to dm the user who used the command but it doesn't seem to work can someone explain what i did wrong?我试图将它发送给使用该命令的用户,但它似乎不起作用有人可以解释我做错了什么吗?

@client.event
async def on_message(message):
    if isinstance(message.channel, discord.DMChannel):
        channel = client.get_channel(942903733262626836)
        await channel.send(f"{message.author} sent:\n```{message.content}```")
    await client.process_commands(message)

@client.command()
async def feedback(ctx, user: discord.User, *, message='Hello please let us know about your about your feedback.'):
    message = message
    await user.send(message)
    await ctx.send('DM Sent Succesfully.')

If feedback is a command that the user has to write (ex. !feedback) then you can just use ctx.author.send() which will send the dm to the author of the command.如果feedback是用户必须编写的命令(例如!反馈),那么您只需使用ctx.author.send()即可将 dm 发送给命令的作者。 What are you trying to do with the on_message function?你想用on_message function 做什么?

@client.command()
async def feedback(ctx, message='Hello please let us know about your about your feedback.'):
    await ctx.author.send(message)
    await ctx.send('DM Sent Succesfully.')

You made user an argument to the command & you're DMing that person instead of the author.您使user成为命令的参数,并且您正在 DMing那个人而不是作者。

async def command(ctx, user: discord.User, ...)

must be used as必须用作

!command @user

where @user pings the user that will be DM'ed . @user ping将被 DM'ed的用户。

You said you wanted to DM the person that used the command, which is the author, so you should DM them instead.你说你想私信使用命令的人,也就是作者,所以你应该私信他们。 You can access the author using ctx.author , and DM them the same way you just DM'ed the other user.您可以使用ctx.author访问作者,并以与其他用户直接私信的方式私信他们。

# Instead of
await user.send(...)
# use
await ctx.author.send(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM