【发布时间】:2021-05-05 05:05:16
【问题描述】:
我尝试了很多其他人的解决方案,但都没有奏效。 那么,如何获得在 MS 中显示 ping 的 ping 命令?
这是我的代码,我没有收到任何错误,但它只是不回复我的 CMD。
import os
from keep_alive import keep_alive
from discord.ext import commands
import time
import random
bot = commands.Bot(
command_prefix="!", # Change to desired prefix
case_insensitive=True # Commands aren't case-sensitive
)
bot.author_id = 777526936753799189
@bot.event
async def on_ready():
print("I'm in")
print(bot.user)
@bot.event
async def on_member_join(member):
await member.create_dm()
await member.dm_channel.send(
f'Hi {member.name}, welcome to my Discord server!'
)
@bot.event
async def on_message(message):
if '!test' in message.content.lower():
await message.channel.send('heyo')
@bot.command()
async def ping(ctx):
await ctx.channel.send(f"{client.latency}")
@bot.command()
async def test(ctx, arg):
await ctx.send(arg)
extensions = [
'cogs.cog_example'
]
if __name__ == '__main__':
for extension in extensions:
bot.load_extension(extension)
keep_alive()
token = os.environ.get("DISCORD_BOT_SECRET")
bot.run(token)
为了简单起见,这里是我用来获取 ping 响应的命令。
@bot.command()
async def ping(ctx):
await ctx.channel.send(f"{client.latency}")
【问题讨论】:
标签: python api discord discord.py ping