[英]Discord.py bot replies itself(it detects its own messages)
@client.event
async def on_message(message):
content = message.content
author = message.author
print("{}: {}".format(author, content))
if message.content.startswith(".play"):
pass
elif message.content.startswith(".echo"):
content = message.content
#
"""
msg = message.content.split()
await message.delete()
output = ""
for word in msg[1:]:
output += word
output += " "
if "gay" in output:
await message.channel.send("Only the gay person is godlessarp")
else:
await message.channel.send(output)
#
"""
import random as r
words = ["..."]
word = r.choice(words)
user_input = ""
i = 0
guesses = 8
hint = ""
for i in range(7):
await message.channel.send("Guess the word!")
user_input = content
if guesses > 0:
if user_input == word:
await message.channel.send("YOU FOUND THE WORD!")
break
elif user_input != word:
try:
await message.channel.send("Incorrect!")
hint += word[i]
await message.channel.send("Here is the hint: " + hint)
i += 1
guesses -= 1
user_input = ""
print(i)
print(guesses)
except:
await message.channel.send("Game Over!")
elif guesses == 0:
await message.channel.send("Game Over!")
elif "<@!753572933594775663>" in content:
await message.channel.send("```If you need help please mail ariyurektuna@gmail.com```")
await message.channel.send("```Or you can Dm the high rank members!```")
elif message.content == ".play":
pass
當我編寫 .echo 時,它實際上會自己玩游戲(它會自己回答)我試圖在循環開始時重置內容,但它沒有用。它有時會停止??。另一個問題是我試圖把這個.play 子句上的游戲代碼,但是當我輸入聊天內容時,它沒有響應,也沒有出現錯誤。 所以我注釋了 .echo 代碼並用游戲代碼替換了它。 現在它可以工作但仍然是相同的循環......我找不到防止這種情況的方法,請幫忙!
如果你不想機器人回復自己,你應該添加
@client.event
async def on_message(message):
if message.author.bot:
return
因此,如果消息作者是機器人,它將忽略該消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.