Milkbone
Milkbone

Reputation: 33

discord.py send_message usage

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.

Upvotes: 3

Views: 11673

Answers (1)

Jay Honnold
Jay Honnold

Reputation: 46

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

Upvotes: 1

Related Questions