有麻烦不和.pybot通过on_message()重复自身并修改用户消息

2024-09-27 04:18:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用on_message()命令让bot识别特定类型的消息,并返回该消息的修改版本;下面是一个示例:

import discord
import asyncio
from discord.ext.commands import Bot
from discord.ext import commands
import platform
import logging

logging.basicConfig(level=logging.INFO)

client = Bot(description="Basic Bot by Habchy#1665", command_prefix="!",     pm_help = True)

@client.command()
async def ping(*args):

    await client.say(":ping_pong: Pong!")
    await asyncio.sleep(3)

@client.event
async def on_message(message):

    if message.content.startswith('ABDD'):

        newMessage = message.content[:]

        newMessage.replace("D","C",1)

        await client.send_message(message.channel, "Fixed!")
        await client.send_message(message.channel, newMessage)

    await client.process_commands(message)


client.run('my auth code')

我遇到的第一个问题是我的bot重复消息“Fixed!”不断地“ABDD”直到我关掉它。在

我遇到的第二个问题是它似乎没有将“ABDD”改为“ABCD”

我对整个机器人制作还是个新手,我希望能在这个问题上得到一些帮助。谢谢!在

我用Habchy的BasicBot作为我的bot的框架。在


Tags: fromimportclientasyncio消息messageonlogging
1条回答
网友
1楼 · 发布于 2024-09-27 04:18:50

我不能告诉您是什么导致了重复的消息,但是它没有将ABDD更改为{}是因为str.replace()返回了一个新的字符串,而不是编辑了一个旧的字符串。在

newMessage.replace("D","C",1)改为{}

相关问题 更多 >

    热门问题