我试图使用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的框架。在
我不能告诉您是什么导致了重复的消息,但是它没有将}是因为
ABDD
更改为{str.replace()
返回了一个新的字符串,而不是编辑了一个旧的字符串。在将}
newMessage.replace("D","C",1)
改为{相关问题 更多 >
编程相关推荐