本文整理汇总了Python中discord.Client.wait_for_message方法的典型用法代码示例。如果您正苦于以下问题:Python Client.wait_for_message方法的具体用法?Python Client.wait_for_message怎么用?Python Client.wait_for_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord.Client
的用法示例。
在下文中一共展示了Client.wait_for_message方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setowner
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import wait_for_message [as 别名]
def setowner(client: discord.Client, message: discord.Message):
""" Set the bot owner. Only works in private messages. """
if not message.channel.is_private:
return
assert not utils.owner_cfg.data, "An owner is already set."
owner_code = str(random.randint(100, 999))
logging.critical("Owner code for assignment: {}".format(owner_code))
yield from client.say(message,
"A code has been printed in the console for you to repeat within 60 seconds.")
user_code = yield from client.wait_for_message(timeout=60, channel=message.channel, content=owner_code)
assert user_code, "You failed to send the desired code."
if user_code:
yield from client.say(message, "You have been assigned bot owner.")
utils.owner_cfg.data = message.author.id
utils.owner_cfg.save()
示例2: cmd_setowner
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import wait_for_message [as 别名]
def cmd_setowner(client: discord.Client, message: discord.Message):
""" """
if not message.channel.is_private:
return
if client.owner.data:
yield from client.send_message(message.channel, "An owner is already set.")
return
owner_code = str(random.randint(100, 999))
logging.critical("Owner code for assignment: {}".format(owner_code))
yield from client.send_message(message.channel,
"A code has been printed in the console for you to repeat within 60 seconds.")
user_code = yield from client.wait_for_message(timeout=60, channel=message.channel, content=owner_code)
if user_code:
yield from client.send_message(message.channel, "You have been assigned bot owner.")
client.owner.data = message.author.id
client.owner.save()
else:
yield from client.send_message(message.channel, "You failed to send the desired code.")
示例3: start_wordsearch
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import wait_for_message [as 别名]
def start_wordsearch(client: discord.Client, channel: discord.Channel, host: discord.Member, word: str=None):
# Initialize the wordsearch
wordsearch.append(channel.id)
# Wait for the user to enter a word
if not word:
yield from client.send_message(host, "**Please enter a word!**\n"
"The word should be **maximum 32 characters long** and "
"may **only** contain `letters A-Å` and *numbers*.")
reply = yield from client.wait_for_message(30, author=host, check=valid_word)
# Stop the wordsearch if the user spent more than 30 seconds writing a valid word
if not reply:
stop_wordsearch(channel)
yield from client.send_message(channel, "{0.mention} failed to enter a valid word.".format(host))
return
# Start the wordsearch
word = reply.content.lower()
yield from client.send_message(host, "Set the word to `{}`.".format(word))
yield from client.send_message(channel, "{0.mention} has entered a word! {1}".format(host, TUTORIAL))
else:
yield from client.send_message(channel, "{0.mention} made me set a word! {1}".format(host, TUTORIAL))
tries = 0
hint = ""
while channel.id in wordsearch:
reply = yield from client.wait_for_message(60 * 30, channel=channel, check=valid_guess)
# Wordsearch expires after 30 minutes
if not reply:
stop_wordsearch(channel)
yield from client.send_message(channel, "**The wordsearch was cancelled after 30 minutes of inactivity.**\n"
"The word was `{}`.".format(word))
return
guessed_word = reply.content.lower()[:-1]
tries += 1
# Update hint
if guessed_word.startswith(hint):
hint = ""
for i, c in enumerate(guessed_word):
if len(word) - 1 < i:
break
if not c == word[i]:
break
hint += c
# Compare the words
if guessed_word > word:
m = "{0.mention} `{1}` is *after* in the dictionary.".format(reply.author, guessed_word) + \
format_hint(hint)
elif guessed_word < word:
m = "{0.mention} `{1}` is *before* in the dictionary.".format(reply.author, guessed_word) + \
format_hint(hint)
else:
m = ""
if guessed_word.startswith(word):
# User guessed the right word (kind of)
m = "{0.mention} ***got it*** after **{tries}** tries! The word was `{word}`.".format(reply.author,
tries=tries,
word=word)
stop_wordsearch(channel)
asyncio.async(client.send_message(channel, m))