如何解决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():
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')
解决方法
如果您要发送私人消息(直接消息),则可以使用go get gorm.io/gorm
import (
"gorm.io/gorm"
"gorm.io/driver/sqlite" //or whatever driver
)
,而不能使用类似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")
时会检查prefix + dm
和rand_num
并将结果发送给用户。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。