Python discord.py自动将不一致结果作为直接消息发送

Python discord.py自动将不一致结果作为直接消息发送,python,if-statement,conditional-statements,discord,discord.py,Python,If Statement,Conditional Statements,Discord,Discord.py,我想知道如何让这个脚本在特定用户的直接消息上发送结果(赢或输),下面是一个简单的例子: from discord.ext import commands import discord import os from random import * client = commands.Bot(command_prefix = '-') @client.event async def on_ready(): pri

我想知道如何让这个脚本在特定用户的直接消息上发送结果(赢或输),下面是一个简单的例子:

    from discord.ext import commands
    import discord
    import os
    from random import *
    
    client = commands.Bot(command_prefix = '-')
    
    @client.event
    async def on_ready():
      print('Bot Is Ready')
    
    @client.command() #The command in order to execute the script first
    async def dm(ctx):
        
        rand_num = (randint(1, 3))
        win_num = 1
        
        if rand_num == win_num:
            print("number was:", rand_num)
            print("won")
            @client.event
            async def on_win():
                dmessage.send.user("You won!") #Send the won result message via direct message on discord automatically
    
        elif rand_num != win_num:
            print("number was:", rand_num)
            print("lost")
            @client.event
            async def on_lost():
                dmessage.send.user("You lost") #Send the lost result message via direct message on discord automatically
    
    client.run('TOKEN')

如果您想发送私人信息直接信息),您可以使用
成员。创建\u dm
,您不能在\u win或\u lost上使用类似
的内容

@client.command()
async def dm(ctx):
    rand_num = (randint(1, 3))
    win_num = 1
    pm_channel = await ctx.author.create_dm()
    if win_num == rand_num:
        await pm_channel.send("You won!")
    else:
        await pm_channel.send("You lost")
因此在这段代码中,当成员写入
前缀+dm
时,它将检查
rand_num
win_num
,然后将结果发送给用户