我使用discord.py和Python v3.9.0制作了一个 Hello Bot ,我不希望我的机器人读取来自机器人的任何消息。我怎么做?
我试图在 Stack Overflow 上查看其他问题,但它们都是至少 5 年前的问题。
我已经拥有它,因此它不会读取从自身发送的消息。顺便说一句,我的命令前缀是 '
这是我的代码:
import os
import discord
# * Clear the screen
def clear():
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
# * Code
clear()
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("'hello"):
await message.channel.send("Hello!")
if message.content.startswith("'Hello"):
await message.channel.send("Hello!")
if message.content.startswith("'HELLO"):
await message.channel.send("Hello!")
if message.content.startswith("'Hi"):
await message.channel.send("Hello!")
if message.content.startswith("'hi"):
await message.channel.send("Hello!")
if message.content.startswith("'HI"):
await message.channel.send("Hello!")
if message.content.startswith("'hey"):
await message.channel.send("Hello!")
if message.content.startswith("'Hey"):
await message.channel.send("Hello!")
if message.content.startswith("'Greetings"):
await message.channel.send("Hello!")
if message.content.startswith("'greetings"):
await message.channel.send("Hello!")
if message.content.startswith("'howdy"):
await message.channel.send("We're not cowboys!")
if message.content.startswith("'Howdy"):
await message.channel.send("We're not cowboys!")
if message.content.startswith("'Bye"):
await message.channel.send("Bye!")
if message.content.startswith("'bye"):
await message.channel.send("Bye!")
if message.content.startswith("'BYE"):
await message.channel.send("Bye!")
# * Runs the code
client.run("my_token")