亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord.py 自動將不和諧的結果作為直接消息發送

Discord.py 自動將不和諧的結果作為直接消息發送

慕神8447489 2023-07-18 10:16:43
我想知道如何讓這個腳本在特定用戶的直接消息上發送結果(獲勝或失敗),這是一個簡單的示例:    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')
查看完整描述

1 回答

?
紅糖糍粑

TA貢獻1815條經驗 獲得超6個贊

如果您想發送私人消息(直接消息),您可以使用member.create_dm但不能使用類似on_win或 的東西on_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")

所以在這段代碼中,member 當member 寫入時prefix + dm,它會檢查rand_num然后win_num將結果發送給用戶。


查看完整回答
反對 回復 2023-07-18
  • 1 回答
  • 0 關注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號