【发布时间】:2019-01-14 00:53:01
【问题描述】:
所以基本上我有这个简单的“世界聊天”脚本,让拥有我的机器人和一个名为“world_chat”的频道的人在该频道中相互聊天,他们可以接收和发送消息,但这里的问题是,每次他们使用我给出的命令或手动创建一个频道,他们将能够发送消息,其他人可以看到它,但他们将无法看到其他人发送的内容,直到我在 heroku 上重置机器人,我真的没有想要这样做,因为当机器人进入很多服务器时,它会做很多工作。
#This is the script that let's people chat to each other
saki_chans=[]
async def get_saki_chans():
for i in client.servers:
for x in i.channels:
if x.type == discord.ChannelType.text and x.name ==
'world_chat' and x.id not in saki_chans:
saki_chans.append(x.id)
print(saki_chans)
@client.event
async def on_message(message):
if message.server and message.channel.name == 'world_chat' and
message.author.id != client.user.id:
for i in saki_chans:
if i == message.channel.id:
pass
else:
emb=discord.Embed(title='',description='{}'.format(message.content),colour
= discord.Color.gold)
emb.set_author(name= message.author.name)
await client.send_message(discord.Object(id=i),embed=emb)
这是根据命令创建通道的脚本
@client.command(pass_context=True)
async def get_wchat(ctx):
servr = ctx.message.server
await client.create_channel(servr, 'world_chat',
type=discord.ChannelType.text)
我希望当有人说“(前缀)create_wchat”时,它会创建一个名为“world_chat”的频道,但我不必重新启动机器人或脚本,让该人接收其他人发送的消息。
【问题讨论】:
标签: python python-3.x discord.py