简体   繁体   English

我正在尝试用python写一个discord bot,但是我的代码不起作用

[英]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. 我正在尝试用Python编写我的第一个Discord机器人,并且在这部分代码上我需要一些帮助,请记住我是python的新手,大约2周前我开始学习。

    @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" 如果用户说“ example yes”,我希望机器人写“ example2 @user”

You're not await ing bot.say , and that's not how you mention a user (you use the User.mention attribute instead) 您不是await bot.say ,那不是您提到用户的方式(而是使用User.mention属性)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试编写代码以删除我的Discord机器人的所有Discord频道 - I'm trying to make a code to delete all discord channels for my discord bot 我正在尝试编写一个 Python 程序来查找 integer 中的音符数量,但我的代码不起作用 - I'm trying to write a Python program to find the number of notes in an integer, but my code isn't working 试图让我的 discord python 机器人写入文件 - trying to make my discord python bot write to a file Python:我不确定为什么我的 discord 机器人代码会出现此错误 - Python: I'm not sure why my discord bot code is giving this error 我正在 Python 中制作 Discord Ghostpinger 机器人 - I'm making a Discord Ghostpinger bot in Python 如何在 python 代码中隐藏我的 discord 机器人令牌? - how can I hide my discord bot token in python code? 如何修复我的 ctx 不工作(Python 中的 Discord Bot)? - How do I fix my ctx not working (Discord Bot in Python)? 我正在尝试为我的 discord 机器人制作身份验证系统,但我一直收到错误消息 - I'm trying to make an auth system for my discord bot, but I keep getting an error Discord.py | 我正在尝试使用会员名称和会员 ID 解除我的机器人禁令 - Discord.py | I'm trying to make my bot unban with both Member Name and Member ID 我正在尝试用python编写数字猜谜游戏,但我的程序无法正常工作 - I'm trying to write a number guessing game in python but my program isn't working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM