您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python-DM用户不和谐机器人

Python-DM用户不和谐机器人

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

from discord.ext import commands
import discord

bot = 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 commands
import discord

bot = 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")
python 2022/1/1 18:28:44 有280人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶