Python-DM用户不和谐机器人

Python-DM用户不和谐机器人,第1张

Python-DM用户不和谐机器人

最简单的方法是使用

discord.ext.commands
扩展程序。在这里,我们使用转换器来获取目标用户,并使用仅关键字参数作为可选消息来发送目标用户:

from discord.ext import commandsimport discordbot = commands.Bot(command_prefix='!')@bot.command(pass_context=True)async def DM(ctx, user: discord.User, *, message=None):    message = message or "This Message is sent via DM"    await bot.send_message(user, message)bot.run("TOKEN")

对于discord.py的较新的1.0+版本,应使用

send
而不是
send_message

from discord.ext import commandsimport discordbot = commands.Bot(command_prefix='!')@bot.command()async def DM(ctx, user: discord.User, *, message=None):    message = message or "This Message is sent via DM"    await user.send(message)bot.run("TOKEN")


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5632484.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存