我的目标是让消息包含来自预定义列表的单词,它将自动响应消息。我一直试图开始简单并让它响应如果第一个单词在列表中但我继续得到"首先arg必须是str,unicode或tuple,而不是list。对我来说是陌生人,我正在努力学习。因此,我不仅要寻找答案,还要考虑如何以及最新进展。
import discord
import random
from jokes import *
from badwords import *
client = discord.Client()
client.login('username', 'password')
@client.event
def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('~guildwebsite'):
client.send_message(message.channel, 'website {}!'.format(message.author.mention()))
if message.content.startswith('~who'):
client.send_message(message.channel, 'I am the Phoenix Chat Butler{}!'.format(message.author.mention()))
if message.content.startswith('~bdo'):
client.send_message(message.channel, 'https://www.blackdesertonline.com/ {}!'.format(message.author.mention()))
if message.content.startswith('~cmd'):
client.send_message(message.channel, '~guildwebsite, ~who, ~bdo, ~help, ~tellmejoke'.format(message.author.mention()))
if message.content.startswith('~help'):
client.send_message(message.channel, 'The help that you need I cannot give! {}'.format(message.author.mention()))
if message.content.startswith('~tellmejoke'):
client.send_message(message.channel, random.choice(joke_list).format(message.author.mention()))
if message.content.startswith(bad_list):
client.send_message(message.channel, 'Please keep the language down! {}
@client.event
def on_ready():
print('Username')
print(client.user.name)
print(client.user.id)
print('------')
client.run()
这是其导入文件的代码
bad_list= ['word',
'keeping',
'clean',
'pg13']
答案 0 :(得分:3)
if message.content.startswith(bad_list):
startswith
不接受列表作为参数。如果您想确定content
是否以bad_list
的任何元素开头,请使用any
。
if any(message.content.startswith(word) for word in bad_list):