简体   繁体   中英

I'm trying to write a discord bot in python but my code is not working

I'm trying to code my first discord bot in python and I need a bit of help with this piece of code, keep in mind im new to python and I started learning about 2 weeks ago.

    @bot.event
async def on_message(message):
    content = message.content
    author = message.author
    if content == "example yes":
        bot.say("example @%s" % (author))

I want the bot to write "example2 @user" if a user says "example yes"

You're not await ing bot.say , and that's not how you mention a user (you use the User.mention attribute instead)

@bot.event
async def on_message(message):
    content = message.content
    author = message.author
    if content == "example yes":
        await bot.say("example {}".format(author.mention))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM