我在为我的服务器做一个石头剪刀机器人。在我不一致地回答之前,这是很好的。当我输入答案时,我在命令提示符下看到这个错误,而H不知道它意味着什么
AttributeError: 'coroutine' object has no attribute 'content'
C:\Users\tuhin\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py:348: RuntimeWarning: coroutine 'wait_for' was never awaited
await self.on_error(event_name, *args, **kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
这是我的代码:
# bot.py
import os
import discord
from dotenv import load_dotenv
import random
from discord.ext import commands
load_dotenv()
PYTHONTRACEMALLOC = 1
TOKEN = "MTAwOTI1OTYxOTMwNDA5OTkwMQ.Gr-Cgn.L-m3iIIgWXkVvdGbdX3lWun9yetTOAuzIkbGI0"
client = discord.Client()
list = ['rock', 'paper', 'scissors']
@client.event
async def on_ready():
print(f'{client.user.name} has connected to Discord!')
@client.event
async def on_member_join(member):
member.create_dm()
member.dm_channel.send(
f'Hi {member.name}, welcome to my Discord server!'
)
@client.event
async def on_message(message):
if message.author.bot: return
if message.content.lower() == "rps":
await message.channel.send(message.author.mention + " started a game of rps")
def is_correct(m):
return m.author == message.author
user_choice = (client.wait_for('message', check=is_correct)).content
choices = random.choice(list)
print(choices)
if user_choice.lower() == choices:
message.channel.send("Tie!")
elif user_choice.lower() == "rock" and choices == "paper":
message.channel.send("i win, i chose paper")
elif user_choice.lower() == "rock" and choices == "scissors":
message.channel.send("you win, i chose scissors")
elif user_choice.lower() == "scissors" and choices == "paper":
message.channel.send("you win, i chose paper")
elif user_choice.lower() == "scissors" and choices == "rock":
message.channel.send("i win, i chose rock")
elif user_choice.lower() == "paper" and choices == "scissors":
message.channel.send("i win, i chose scissors")
elif user_choice.lower() == "paper" and choices == "rock":
message.channel.send("you win, i chose rock")
client.run(TOKEN)
有人能帮我解决这个问题吗?
发布于 2022-08-17 17:49:19
您需要在这里使用await
来解析协同线:
user_choice = (await client.wait_for('message', check=is_correct)).content
https://stackoverflow.com/questions/73392805
复制相似问题