python - 当我提到它时,让机器人用前缀进行响应

标签 python python-3.x discord discord.py

我希望能够输入“@Cool Boi prefix”,机器人将响应当前的前缀,由于某种原因它不起作用,并且它也没有显示错误消息,我当前的代码是:

@bot.event
async def on_message(message):
    if message.content.startswith('@Cool Boi prefix')
        await bot.say(' The current prefix is👌')

最佳答案

提及的实际文本与 Discord 显示的内容略有不同。检查您是否被提及的一种方法是使用 bot.user. said_in

@bot.event
async def on_message(message):
    if bot.user.mentioned_in(message) and 'prefix' in message.content:
        await bot.send_message(message.channel, f'My Prefix is {bot.command_prefix}')

或者您可以使用 bot.user.mention 构建字符串

@bot.event
async def on_message(message):
    if message.content.startswith(f'{bot.user.mention} prefix'):
        await bot.send_message(message.channel, f'My Prefix is {bot.command_prefix}')

关于python - 当我提到它时,让机器人用前缀进行响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54084366/

相关文章:

python - python中未使用函数的重新定义

python-3.x - 不和谐.py |检查是否有用户加入语音 channel

python - Ansible 中的 if 语句与 Jinja2 变量

python - 忽略 os.listdir() 中的目录

python - 无法在 Plone 4 的导航 portlet 中安排项目顺序

javascript - Discord.io 通过 Discord Bot 发送图像 - NodeJS

python - on_message函数重复,Discord.py重写

Python RegEx,匹配字符串中的单词并获取计数

python - 将 json 数据写入 json 文件时 JSON.parse 错误

python - 是否可以构建一个适用于 Python 2 和 3 的shebang?