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. What are you trying to do with the 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.
async def command(ctx, user: discord.User, ...)
must be used as
!command @user
where @user
pings the user that will be 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.
# Instead of
await user.send(...)
# use
await ctx.author.send(...)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.