如何使我的discord.py重写机器人向消息作者发送私人消息 [英] How to make my discord.py rewrite bot send a Private Message to the message author

查看:215
本文介绍了如何使我的discord.py重写机器人向消息作者发送私人消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为游戏的Discord服务器制作了Discord机器人。我使用的是discord.py重写版本,我想向该消息的作者发送私人消息。

I have made a Discord bot for a game's Discord server. I'm using the discord.py rewrite version and I want to send a private message to the author of the message.

我在互联网上尝试了其他代码,包括一些 @bot代码,但总是会出现错误

I've tried other codes on the internet which includes some "@bot" code, but it always comes up with the error


未定义名称'bot'

"Name 'bot' is not defined"

,如果我尝试 send_message 它会说


客户端对象没有属性'send_message'

"Client object has no attribute 'send_message'"

我的代码:

#I've tried this...

@bot.command(pass_context=True)
async def poke(ctx, message):
    await client.send_message(ctx.message.author, 'boop')

#but it comes up with the error "Name 'bot' is not defined" and stuff like that

例如,我想要创建命令!messageme,如果用户执行了该命令,我希望机器人将私人消息消息的em> author 说刚给你发消息!。

For example, I want to create a command "!messageme", and if a user executes the command I expect the bot to private message the author of the message saying "Just messaged you!".

如果Pierce#9255在服务器中执行了该命令,则机器人应将其私人消息发送给他说刚给您发消息!。

If Pierce#9255 executes the command in the server, the bot should private message him saying "Just messaged you!".

推荐答案

您是否定义了bot变量?如果不是,请执行以下操作:

Did you define your bot variable? If not then do this:

bot = commands.Bot(command_prefix='!') # Just add your desired prefix there.

# sending dm
@bot.command()
async def poke(ctx):
    await ctx.author.send('boop!')

此外,如果您仍然感到困惑,则可以尝试以下本教程:-NiByO6h7Ck

Also, if you still confused then just give this yt tutorial a try: -NiByO6h7Ck

这篇关于如何使我的discord.py重写机器人向消息作者发送私人消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆