问题
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.
I've tried other codes on the internet which includes some "@bot" code, but it always comes up with the error
"Name 'bot' is not defined"
and if I try send_message
it says
"Client object has no attribute 'send_message'"
My code:
#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
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!".
If Pierce#9255 executes the command in the server, the bot should private message him saying "Just messaged you!".
回答1:
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!')
Also, if you still confused then just give this yt tutorial a try: -NiByO6h7Ck
回答2:
Firstly you have to define the Bot
. The you will have to DM a user.
bot = commands.Bot(command_prefix='your_prefix')
@bot.command()
async def hello(ctx):
user = ctx.author
await user.send("Hello!")
来源:https://stackoverflow.com/questions/55935047/how-to-make-my-discord-py-rewrite-bot-send-a-private-message-to-the-message-auth