当我用 python lib Discord-py-api 编写一个不和谐的自动回复器时,它看起来好像没有检测到收到的消息...
我的代码:
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
if message.author == self.user:
return
else:
await message.channel.send(self.user + ' is not here now. Please message later. Thank you.')
print('One message replied to ' + message.author)
print("""
---------------------------------------------------------------------------
Discord-auto-replier
By orangetheorange
https://github.com/orangetheorange/discord-replier
---------------------------------------------------------------------------
[*] Thank you for using, if you find any bugs, please report to me.
[*] Please read token.md for your discord token.
[!] If you enter a token, please keep it secretly, if someone has it he can
have full access to your account.
""")
global token
token = ""
with open('token.txt', 'r', encoding='utf-8') as tok:
if tok.read() == "":
with open('token.txt', 'w', encoding='utf-8') as tok:
token = input('Put your discord token here: ')
tok.write(token)
else:
with open('token.txt', 'r', encoding='utf-8') as toke:
token = toke.read()
print('Used token: ' + token)
intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run(token)
我尝试更改一些小细节,例如删除“.channel”,但没有任何效果。它甚至没有打印收到消息时回复的消息...我希望它能够正常工作,它会自动回复.
其实你并不需要将其放入 MyClient 中。只要这样做:
@client.event
async def on_message(message):
if message.author.bot:
return
else:
await message.channel.send(f'{message.author} is not here now. Please message later. Thank you.')
print(f'One message replied to {message.author}')