【发布时间】:2019-03-25 18:13:45
【问题描述】:
我如何获得频道的名称,以便此机器人可以在其放置的任何服务器上工作,而无需更改代码? (在我放“我在这里放什么”的代码中,我希望名称出现在变量中)谢谢
from discord.ext.commands import Bot
import time, asyncio
TOKEN = 'Its a secret'
BOT_PREFIX = ["!"]
client = Bot(command_prefix=BOT_PREFIX)
@client.event
async def on_message(message):
if message.author == client.user:
return
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
await start()
while True:
currentTime = time.strftime("%M%S", time.gmtime(time.time()))
if currentTime == "30:00":
await start()
await asyncio.sleep(1)
async def start():
mainChannel = #What do i put here?
print(mainChannel.name)
await client.send_message(mainChannel, "Starting countdown", tts = True)
client.run(TOKEN)
【问题讨论】:
-
当您只知道它的名称时,您是否正在尝试获取
Channel对象?您如何选择要发送消息的服务器?你有这个频道的ID吗? -
我想把它发送到机器人所在的所有服务器的主频道,所以我没有任何 id。理想情况下,它会寻找名称为“一般”或“主频道”的频道
标签: python discord discord.py