Discord 单词过滤机器人不会删除任何内容
我为我们的一位成员制作了一个discord.py 机器人,作为一个笑话。我测试了一下,它根本不起作用。有人可以告诉我这段代码有什么问题吗?
from http import client
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
client.run(TOKEN)
@client.event
async def on_message(message):
await client.process_commands(message) # add this if also using command decorators
if message.author.id == 300677572683890688 and "tranime" in message.content.lower():
await message.delete()
await message.channel.send(f"You are in the process of behavioural therapy. please do not attempt to bypass it, {message.author.mention}")
I made a discord.py bot for one of our members, as a joke. im testing it out and it doesnt work at all. can someone tell me what can be wrong with this code?
from http import client
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
client.run(TOKEN)
@client.event
async def on_message(message):
await client.process_commands(message) # add this if also using command decorators
if message.author.id == 300677572683890688 and "tranime" in message.content.lower():
await message.delete()
await message.channel.send(f"You are in the process of behavioural therapy. please do not attempt to bypass it, {message.author.mention}")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
构建机器人的结构在很多方面都是错误的,这可能会导致错误。
要运行机器人,
始终位于代码的末尾!
要处理命令,您可以将命令放在
on_message
事件的末尾,尽管这里不需要这样做,因为您只需使用discord.Client()
。新的结构可能是:
代码也应该正确缩进,否则可能会出现问题。
The structure, how you build the bot, is wrong in many ways, that could cause the error.
To run the bot,
always belongs at the end of your code!
To process commands, you put
at the end of your
on_message
event, even though this is not necessary here as you just usediscord.Client()
.A new structure could be:
The code should also be indented correctly, otherwise there may be problems.