本文整理汇总了Python中discord.Client.edit_message方法的典型用法代码示例。如果您正苦于以下问题:Python Client.edit_message方法的具体用法?Python Client.edit_message怎么用?Python Client.edit_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord.Client
的用法示例。
在下文中一共展示了Client.edit_message方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ping
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import edit_message [as 别名]
def ping(client: discord.Client, message: discord.Message):
""" Tracks the time spent parsing the command and sending a message. """
# Track the time it took to receive a message and send it.
start_time = datetime.now()
first_message = yield from client.say(message, "Pong!")
stop_time = datetime.now()
# Edit our message with the tracked time (in ms)
time_elapsed = (stop_time - start_time).microseconds / 1000
yield from client.edit_message(first_message,
"Pong! `{elapsed:.4f}ms`".format(elapsed=time_elapsed))
示例2: on_command
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import edit_message [as 别名]
def on_command(client: discord.Client, message: discord.Message, args: list):
if args[0] == "!decide":
if len(args) > 13:
yield from client.send_message(message.channel, "I can't roll that many decisions.")
return
if len(args) > 2:
choices = args[1:]
rolls = randint(len(choices) * 3, len(choices) * 7)
sleep_time = 0
sleep_change = 2 / (rolls / 2)
m = ""
# Roll and send
for i in range(rolls):
if i > rolls / 2:
sleep_time += sleep_change
# Select next choice
choice = choices[i % len(choices)]
if not m:
m = yield from client.send_message(message.channel, "`" + choice + "`")
else:
try:
m = yield from client.edit_message(m, "`" + choice + "`")
except discord.errors.HTTPException:
pass
if sleep_time:
sleep(sleep_time)
yield from client.edit_message(m, "**" + m.content[1:-1] + "**" +
" {}".format(message.author.mention))
else:
yield from client.send_message(message.channel, "Please see `!help decide`.")
示例3: on_command
# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import edit_message [as 别名]
def on_command(client: discord.Client, message: discord.Message, args: list):
# Basic check
if args[0] == "!ping":
start = datetime.now()
pong = yield from client.send_message(message.channel, "pong")
end = datetime.now()
response = (end - start).microseconds / 1000
yield from client.edit_message(pong, "pong `{}ms`".format(response))
logging.info("Response time: {}ms".format(response))
# Roll from 1-100 or more
elif args[0] == "!roll":
if len(args) > 1:
try:
roll = random.randint(1, int(args[1]))
except ValueError:
roll = random.randint(1, 100)
else:
roll = random.randint(1, 100)
yield from client.send_message(message.channel, "{0.mention} rolls {1}".format(message.author, roll))
# Handle bot feature requests
# (warning: this code is not representative of what I stand for in programming. I'm sorry.)
elif args[0] == "!feature":
m = "Please see `!help feature`."
if len(args) > 2:
plugin = args[1]
if client.has_plugin(plugin):
# Initialize the plugin for features
if plugin not in feature_reqs.data:
feature_reqs.data[plugin] = []
req_list = feature_reqs.data[plugin]
# List feature request
if args[2].startswith("#"):
feature_id = get_req_id(args[2])
if feature_id is not None:
if 0 <= feature_id < len(req_list):
m = "```diff\n" + format_req(plugin, feature_id) + "```"
else:
m = "There is no such feature. Try `!feature {} list`.".format(plugin)
# List all feature requests or request with given ID.
if args[2] == "list":
m = "```diff\n"
for req_id in range(len(req_list)):
m += format_req(plugin, req_id) + "\n"
m += "```"
# Create a new feature
elif args[2] == "new" or args[2] == "add" and len(args) > 3:
feature = " ".join(args[3:]).replace("\n", " ")
if feature not in req_list:
feature_reqs.data[plugin].append(feature)
feature_reqs.save()
m = "Feature saved as `{}` id **#{}**.".format(plugin, len(req_list))
# Owner commands
if client.is_owner(message.author):
# Mark a feature as complete
if args[2] == "mark" and len(args) > 3:
feature_id = get_req_id(args[3])
if feature_id is not None:
if 0 <= feature_id < len(req_list):
req = feature_reqs.data[plugin][feature_id]
if not req.endswith("+++"):
feature_reqs.data[plugin][feature_id] += "+++"
feature_reqs.save()
m = "Marked feature with `{}` id **#{}**.".format(plugin, feature_id + 1)
else:
feature_reqs.data[plugin][feature_id] = req[:-3]
feature_reqs.save()
m = "Unmarked feature with `{}` id **#{}**.".format(plugin, feature_id + 1)
else:
m = "There is no such feature. Try `!feature {} list`.".format(plugin)
# Remove a feature request
elif args[2] == "remove"and len(args) > 3:
feature_id = get_req_id(args[3])
if feature_id is not None:
if 0 <= feature_id < len(req_list):
feature_reqs.data[plugin].pop(feature_id)
feature_reqs.save()
m = "Removed feature with `{}` id **#{}**.".format(plugin, feature_id + 1)
else:
m = "There is no such feature. Try `!feature {} list`.".format(plugin)
#.........这里部分代码省略.........