@client.command()
@commands.is_owner()
async def broadcast(ctx, message):
for guild in client.guilds:
# get the owner of guild
owner = guild.owner
# check if dm exists, if not create it
if owner.dm_channel is None:
await owner.create_dm()
# if creation of dm successful
if owner.dm_channel != None:
await owner.dm_channel.send(message)
for channel in guild.channels:
if(channel.name == 'general'):
await channel.send(message)
要直接向成员发送消息,需要获取
member
对象的dm_channel
。您可以通过使用member.dm_channel
来实现这一点。只需使用guild.owner
作为member
并使用dm通道发送消息。您应该启用
discord.Intents.guild
和discord.Intents.members
,以便bot获得guild.owner
相关问题 更多 >
编程相关推荐