【发布时间】:2021-11-23 23:17:12
【问题描述】:
我有一个程序可以更改频道成员在一天中的特定时间可以看到的内容。为此,我可以更改每个成员的角色,或者更改每个频道的权限。但是,我已经查看了整个网络,并且任何一种方法的所有方式都需要发送一条消息,以便可以读取来自该消息的数据并将其放入函数中,例如:
@client.command()
async def perm(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False
Change the permissions of a discord text channel with discord.py
或
async def addrole(ctx):
member = ctx.message.author
role = get(member.server.roles, name="Test")
await bot.add_roles(member, role)
Discord.py | add role to someone
我当前的程序如下所示:
import discord
client = discord.Client()
import datetime
async def live_day(schedule):
current_place = "the void"
while True:
current_time = str((datetime.datetime.now() -datetime.timedelta(hours=7)).time())
int_time = int(current_time[:2] + current_time[3:5])
for x in range(len(schedule)):
try:
start_time = schedule[x][1]
end_time = schedule[x + 1][1]
except IndexError:
end_time = 2400
if current_place != schedule[x][0] and int_time >= start_time and int_time < end_time:
current_place = schedule[x][0]
#Change the channel permissions of the current place to allow viewing
#Change the channel permissions of the last channel to disallow viewing
@client.event
async def on_ready():
print("{0.user} has arrived for duty".format(client))
client.loop.create_task(live_day([
("Home", 0),
("Work", 900),
("Home", 1700),
("Nightclub", 2000),
("Home", 2200),
]))
client.run(my_secret)
别介意写得不好的代码,我该怎么做,或者我应该去哪里解决这个问题?任何帮助表示赞赏。谢谢!
编辑:我可以使用这个单独获取频道,
channel1=client.get_channel(channelid)
discord.py, send message by channel id without on_message() event?
但是我不能将它用于多个服务器。如何按名称获取频道?
【问题讨论】:
标签: discord.py