【发布时间】:2021-05-19 13:07:15
【问题描述】:
我正在尝试编写一个 discord 机器人,它会在发送的每条消息中检查单词“pawel”,如果找到,它应该向名为 #pawel 的 discord 文本频道发送一条消息。如果没有,它应该创建它。现在我被这个愚蠢的错误困住了:
We're live!
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 22, in on_message
channel = discord.utils.get(guild.text_channels, name='pawel')
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/utils.py", line 269, in get
for elem in iterable:
TypeError: 'property' object is not iterable
机器人的完整代码在这里:
import discord
import os
client = discord.Client()
guild = discord.Guild
@client.event
async def on_ready():
print("We're live!")
pawel = ('pawel')
@client.event
async def on_message(message):
if message.author == client.user:
return
if pawel in message.content:
channel = discord.utils.get(guild.text_channels, name='pawel')
channel.id = channel.id
if channel == None:
await guild.create.text_channel('pawel')
await message.channel.send('pawel')
client.run(os.getenv('TOKEN'))
我什么都试过了!
【问题讨论】:
标签: python discord discord.py typeerror