将变量发送到discord通道Python



所以我有这个代码:

while True:
recent_post = api.user_timeline(screen_name = 'PartAlert', count = 1, since_id=recent_id, include_rts = True, tweet_mode='extended')
if recent_post:
last_post = recent_post[0].full_text
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', last_post)
if urls:
print(f"[{datetime.datetime.now()}] Link(s) Found:")
for x in range(len(urls)):
if urls[x][-1] == ':':
urls[x] = urls[x][:-1]
print(urls[x])
recent_id = recent_post[0].id
time.sleep(10)

它获取特定用户的twitter帖子。我现在想要的是url变量将发送到不和谐通道,但无论我尝试什么,它都不起作用。有什么想法吗?

请确保将send_url方法放置在调用send_url的行上方(或者可以使用类,但这可能需要重新设计机器人程序(。

要向频道发送消息,您可以使用:

channel_id = # some channel id here
message = # some message here
channel = client.get_channel(channel_id)
await channel.send(message)

你也可以像一样定义send_url

async def send_url(channel_id, message):
channel = client.get_channel(channel_id)
await channel.send(message)

只需确保将它放置在调用该方法的行的上方即可。

最新更新