3 回答
TA贡献1824条经验 获得超8个赞
一种更精确的方法是使用TextChannelConverter
它在提供 ID/名称/提及时返回通道,而不仅仅是名称
from discord.ext import commands
async def log(ctx, *, args=None):
if not args:
await ctx.send("Please provide the channel to set the logs")
return
try:
channel = await commands.TextChannelConverter().convert(ctx, args)
except:
return await ctx.send("Channel Not Found")
#channel is not a TextChannel object, save its ID or send or whatever you want to do
TA贡献1827条经验 获得超4个赞
我认为它可以基于此工作。
@commands.command()
async def test(self, ctx, channel=None):
channel2 = self.client.get_channel(id=int(channel))
if type(channel2) != discord.channel.TextChannel:
await ctx.send('Please do not enter an audio channel')
else:
await ctx.send('Perfect.')
TA贡献1966条经验 获得超4个赞
Return 只是结束您可以使用它而不是 if 语句的函数。我不知道使用的是什么 JSON 文件,我希望这会有所帮助
async def log(ctx, *, args=None):
if not args:
await ctx.send("Which channel should I set the logs? :thinking:")
return
for channel in ctx.guild.channels:
if channel.name == args:
await ctx.send('Found your channel')
# channel is now an object, you can do what you want here
await channel.send('This is the channel wanted')
return
await ctx.send("Can't find your channel")
添加回答
举报