discord.py send_message usage

99封情书 提交于 2019-12-12 22:09:20

问题


I've started working on a project to accelerate my learning of python. I'm trying to recreate a discord bot I use quite a bit since i'm already use to its features. Below is my current code

import discord
from discord import User
from discord.ext.commands import Bot

import secrets

pybot = Bot(command_prefix = "!")

@pybot.event
async def on_read():
    print("Client logged in")

@pybot.command()
async def hello(*args):
    print(User.display_name)
    return await pybot.say("Hello, world!")

@pybot.command()
async def truck(*args):
    await pybot.send_message(message.user,'Watchout for that truck!')

pybot.run(secrets.BOT_TOKEN)

what im trying to get to happen is when someone types the command !truck <mention user> it sends a message to that mentioned user with the message "Watch out for that truck!".

I'm getting the following error:

Command raised an exception: NameError: name 'message' is not defined

I've tried looking up examples of what im trying to do but haven't found much, or am not understanding what I should be doing. Hopefully this isn't a repost of a similar question

Thanks.


回答1:


The *args in your truck is no longer valid syntax I believe for the commands with discord.py

@pybot.command(pass_context=True)
async def truck(ctx):
    await pybot.send_message(ctx.message.user, 'Watchout for that truck!')

Checkout the github repository for Discord.py with their examples



来源:https://stackoverflow.com/questions/41970789/discord-py-send-message-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!